Reputation: 6973
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 ?
Upvotes: 2
Views: 545
Reputation: 9189
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.
Upvotes: 3
Reputation: 1559
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.
Upvotes: 1