Do Android AlarmManagers continue to run after an app update?
Asked Answered
D

2

12

From what I can see, if you schedule an indefinitely repeating alarm it won't stop running until you reboot your device or uninstall the app.

I was wondering, how do these behave in the event of an app update? i.e. you download version 1 of the app from Play Store, for example, and run the app and this alarm starts running. Then version two is released and an auto or manual update is performed. Does this alarm still keep running (or must you start up the app again to start the alarm)?

In my scenario I do need it to do so, so I am hoping that the answer is that it would just keep running. However, what happens then if you changed the alarm code in version 2?

Diastema answered 2/7, 2014 at 0:16 Comment(1)
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.Mythicize
P
19

The answer appears to be that the AlarmManager alarms do keep running after an app update for most versions of Android. Certainly for Android 2.2 or above. The UninstallReceiver in AlarmManagerService was updated to handle package update without killing the alarms - see here where there's the explicit comment:

// This package is being updated; don't kill its alarms.

The code to handle this wasn't in the 2.1 AlarmManagerService.UninstallReceiver

I realize this probably comes the best part of 3 years too late to help the OP, but hopefully it might help others.

Pyrostat answered 1/2, 2017 at 16:44 Comment(0)
S
1

Do something like this.

Essentially, if every time your app starts you re-run your PendingIntent with the same ID, if it was running nothing will happen and if it wasn't running it will start running.

This way you don't have to worry about losing your alarm after an update.

Sasser answered 19/7, 2014 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.