Take the 2-minute tour ×

I have an android application, that runs a standalone service. Now, I do set some alarms in my service. I want to cancel all these alarms when my application gets uninstalled.

I tried putting code for cancelling all alarms in OnDestroy() but it is not guaranteed to be called. Is there any reliable way to cancel all alarms when application is unistalled ?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If your app is uninstalled there will be nothing to handle the PendingIntent of the alarms you set. So they will be broadcast but no one will handle them and the system remove them. If you're concerned about different versions of your app handling the alarm differently after being reinstalled add a version extra to your pending intent.

share|improve this answer

There is no way to run code on uninstall unfortunately. I would say onDestroy() is likely to be called on uninstall as the service will be finalized if it is running at the time. One thing I do not know is if the OS automatically cancels alarms associated with the app on uninstall.

share|improve this answer
I would guess that they're cancelled for you, but I don't actually know this for certain. –  David Caunt Jul 25 '11 at 22:54
During uninstalls, alarms seem to be cancelled automaticlly on ICS but not on froyo, haven't tested on other systems. –  technoguff Aug 3 '12 at 5:41

Your Answer


