I need to cancel a repeating alarm when my app terminates. The problem is I have several activities and since they can be killed at any time, how can I determine when the last activity is being shutdown so I can call my alarm canceling method?
A:
There's no 100% reliable way. The best thing you can do is subclass Application
and override onTerminate()
.
alex
2010-06-30 17:46:10
Of course, there's no guarantee onTerminate() will ever get called either. And alarms only get removed if the OS reboots. So Im thinking now that I best not use setRepeating() in AlarmManager. Maybe Im better off scheduling the next alarm inside my alarm handler and have it check to see if app is running?
Eno
2010-06-30 18:31:19
@Eno I think yes. `AlarmManager` is likely starting a `Service`, right? Make sure it doesn't bring the `Application` up.
alex
2010-06-30 19:13:20