I made a Service
that uses a Thread
when it is started. I want to keep the service running when my application is closed (START_STICKY
).
To make the service keep running, I have to return START_STICKY
:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread( new Runnable() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
return START_STICKY;
}
How can I return it with my thread?