开发者

Android : cancel alarms when service is uninstalled

I have an android application, that runs a standalone service. Now, I do set some alarms in my service. I want开发者_如何学JAVA 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 ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜