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?
Start an alarm when the device restarts This ensures that the AlarmManager will continue doing its task without the user needing to manually restart the alarm.
AlarmManager is a bridge between application and Android system alarm service. It can send a broadcast to your app (which can be completely terminated by user) at a scheduled time and your app can then perform any task accordingly.
Calendar object is used to store one specific date. Therefore, in order to get set alarms for several days, you need to set each of the alarms separately. For this reason you may create separate Calendar objects or reuse one by changing the time. However, you have same receiver class for both alarms.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With