android CountDownTimer
Below is the problem i am facing at the moment.
i have an activity lets say A. On button(lets say B1) click in activity A i have started CountDownTimer and when user click's button(lets say B2) i have started new activity let's say B. My problem is that once timer onFinish is called i need 开发者_运维知识库to finish activity B.
i have searched many forums and internet but couldnt find solution.
Please help to solve this problem.
Regards
There are a couple of options:
- http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29: onNewIntent() requires that Activity B be singleTop. If it is you can just launch an Intent with a special flag that Activity B will receive and then destroy itself.
- You can register a broadcast receiver in Activity B and then send a broadcast in Activity A (see http://developer.android.com/reference/android/content/BroadcastReceiver.html)
- You can pass the timer limit to Activity B, start the timer in Activity B and not have to worry about it at all.
- My personal favorite: http://developer.android.com/reference/android/os/Handler.html. Have Activity B create a public static Handler instance, and then have Activity A send it a Message once the timer expires. Moderately messy, but very quick.
精彩评论