i have this thread which run as a service:
public void run() {
try {
while(true) {
Thread.sleep(timeInterval);
results = sendGetMessage();
b.putString("results", results);
receiver.send(2, b);
}
} catch (InterruptedException e) {
results = e.toString();
}
this.stop();
}
i want to write a simple function which will check if my application is still running (in order to replace the everlasting while(ture) i’ve written).
something like: while(isMyAppRunning).
my problem now that even when i’m closing the app, the service keep on running..
can someone please be kind and give me a code example?
Do it the other way around. Make a boolean flag
runningin thisThreadsubclass. Start it astrueand expose ashutdown()method which sets it tofalse. Call this method from yourActivity‘sonPause()method.