Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class MyService extends Service {
private static final String TAG = MyService.class.getSimpleName();
private ArrayList<Object> objects;
public MyService() {
}
@Override public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override public int onStartCommand(Intent intent, int flags, int startId) {
objects = new ArrayList<>();
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
Thread thread = new Thread(new Runnable() {
@Override public void run() {
wakeLock.acquire();
for (int i = 0; true; i++) {
Log.d(TAG, "run: Working " + i);
try {
Thread.sleep(2000L);
for (int j = 0; j < 10000; j++) {
objects.add(new Rect(10, 10, 10, 10));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
thread.start();
return super.onStartCommand(intent, flags, startId);
}
@Override public void onLowMemory() {
Log.d(TAG, "onLowMemory: ");
}
@Override public void onTrimMemory(int level) {
Log.d(TAG, "onTrimMemory: " + level);
}
@Override public void onDestroy() {
Log.d(TAG, "onDestroy: ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment