0

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();
4

2 回答 2

1

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.

于 2013-06-01T02:50:54.710 回答
0

CountDownTimer即使活动 onDestroy() 被调用并且将被调用,它仍然处于活动forSend()状态onFinish();只需在 onTick 上输入一个日志,您就会看到。但是,如果您终止应用程序,则该进程将被终止,并且 CountDownTimer 也将被终止。

于 2013-06-01T02:43:39.383 回答