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?

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.
    – Caleb Koch
    Commented Jun 27, 2023 at 13:49

2 Answers 2

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.