Code execution when application is updated / reinstalled

I have some alarms set through the AlarmManager to perform some periodic tasks. I set / reset them when the user opens the application for the first time and in every boot_complete event. But when the application is reinstalled via ADB, my alarms no longer work. it looks like the OS is removing alarms when you reinstall the application. I assume that this will happen if the user also updates the application from the market.

If I can get a broadcast or some kind of callback in case of reinstallation / update, etc. of my application, I can set alarms again. but I don’t know if this is possible or how? Can someone please help me.

+4
source share
1 answer

Yes it is possible.

You can create a broadcast receiver that listens for any PACKAGE_* events that the system sends, but you do not receive them for your own application, except when your application is updated - you will receive PACKAGE_REMOVED , shortly after which PACKAGE_REPLACED .

+5
source

Source: https://habr.com/ru/post/1299496/


All Articles