Reputation: 35
I use the CountDownTimer
to send a message. I wonder does this work if I close the app?
Here is my code:
new CountDownTimer(waitTime*1000, 1000) {
public void onTick(long millisUntilFinished) {}
public void onFinish() { forSend(); }
}.start();
Upvotes: 0
Views: 2001
Reputation: 18151
The CountDownTimer
is still active even if the activity onDestroy() is called and forSend()
would be called in onFinish()
; Just put a log in onTick and you will see. However if you kill the app then the process would be killed and the CountDownTimer would also be killed.
Upvotes: 0
Reputation: 408
Remember that when you "close" an app is not necessary a "dead" app, when an app dissapear completely from the screen it goes to Stop state (calling onPause() and then onStop()) , then it take some time to call onFinish(), after that the app no longer exist as a reacheable app from directly onStart() to be called without making the onCreate() again, so as far as the timer still counting your app will be "alive" waiting for the counter to end and call the forSend() at onFinish() (the onFinish() from your annonymous CountDownTimer object) and the last thing the app do is the onFinish() from Activity Class of course, even if you overwrite it or not.
Upvotes: 1