Im working on an app that uses AlarmManager
for some processes. I wanted to ask that if i update my app on the playstore. (update not new install) will registered alarms get canceled? Also will values of SharedPreference
get reset?
Asked
Active
Viewed 1,500 times
8

Sandip Fichadiya
- 3,430
- 2
- 21
- 47

Shweta Dhingana
- 133
- 7
-
2Does this answer your question? [Android - Alarm lost after app update](https://stackoverflow.com/questions/24088431/android-alarm-lost-after-app-update) – Bink Oct 09 '20 at 17:42
1 Answers
9
Alarms: Yes, they will get canceled but you can restart your alarms.
Here is the solution from this post https://stackoverflow.com/a/34464059/3474021
Have a broadcast receiver registered within your app with 2 intent filters namely:
android.intent.action.BOOT_COMPLETED
(docs) - called when your device restarts. Alarms are cancelled when device is shut down.android.intent.action.MY_PACKAGE_REPLACED
(docs) - called once your app is reinstalled or updated from play store or from any source.
You will also need the permission android.permission.RECEIVE_BOOT_COMPLETED
to receive android.intent.action.BOOT_COMPLETED
. In this receiver you can start your alarms again.
SharedPreferences: No, they will remain when an app is updated.

Victor Häggqvist
- 4,484
- 3
- 27
- 35

wprenison
- 544
- 4
- 11
-
-
7Do you have a reference documenting that alarms are in fact cleared when the app is updated? I don't see this mentioned in the AlarmManager docs, and when I install an updated version locally, the alarms are still present. – hustoj2 Oct 15 '19 at 19:52
-
@hustoj2 I concur! Just did a test on API33 by capturing a before and after as it relates to catching ACTION_MY_PACKAGE_REPLACED and all alarms were retained afterward! – Bink May 18 '23 at 23:48
-
With or without using the `MY_PACKAGE_REPLACED` solution: something strange that I noticed was that if, during development, the app is re-installed by running the app via Android Studio, previously scheduled alarms go away. However, if you use `adb` to install the APKs generated by Android Studio, the alarms don't go away. – Caleb Koch Jun 27 '23 at 13:50
-