I have a thread that running into an activity. I don't want that the thread continuos running when the user click the home button or, for example, the user receive a call phone. So I want pause the thread and resume it when the user re-opens the application. I've tried with this:
protected void onPause() {
synchronized (thread) {
try {
thread.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
super.onPause();
}
protected void onResume() {
thread.notify();
super.onResume();
}
It stops the thread but don't resume it, the thread seems freezed.
I've also tried with the deprecated method Thread.suspend()
and Thread.resume()
, but in this case into Activity.onPause()
the thread doesn't stop.
Anyone know the solution?
wait
andnotifyAll
methods on an Object into the thread and not directly on the thread-object? – Mollymollycoddle