views:

38

answers:

1

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
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
@Eno I think yes. `AlarmManager` is likely starting a `Service`, right? Make sure it doesn't bring the `Application` up.
alex