Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Android AlarmManagers continue to run after an app update?

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?

like image 296
brent777 Avatar asked Jul 02 '14 00:07

brent777


People also ask

Does Alarm Manager persist even after reboot?

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.

What is Android Alarm Manager?

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.

How do I set an alarm for multiple days on Android?

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.


2 Answers

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.

like image 78
HexAndBugs Avatar answered Sep 18 '22 12:09

HexAndBugs


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.

like image 41
Molten Ice Avatar answered Sep 22 '22 12:09

Molten Ice