Jomo
Jomo

Reputation: 111

Why does Android's alarm manager forgets alarms?

I set alarms to notify the user on different times. I check with "adb shell dumpsys alarm" and they look like

RTC_WAKEUP #2: Alarm{433c7328 type 0 com.app.package} type=0 whenElapsed=89936417 when=+9h8m5s417ms window=-1 repeatInterval=0 count=0 operation=PendingIntent{42e8e7f8: PendingIntentRecord{42deb070 com.app.package broadcastIntent}}

Sometimes they stay and work for at least 2 days (I didn't test longer), sometimes they are all gone after a few hours or so, even before the first notification should have taken place and "adb shell dumpsys alarm" doesn't show any of my entries anymore. (I tested with 2 devices, Android 4.0 and 4.4)

I do know that the alarm manager forgets the entries after a reboot of the device and I took care of this case and re-add them afterwards. But obviously there are other cases when the alarm manager forgets entries without having rebooted. I would like to know which cases these are and how to handle them.

Upvotes: 2

Views: 992

Answers (1)

Alireza Rahimi
Alireza Rahimi

Reputation: 509

From AlarmManager

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
it will work until your application has been killed or device has been rebooted.(If you removed an application from recent list, or from Application Manager you kill the app. That means you are force fully killed the application. and Then AlarmManager of your application has been removed.)
in some cases when your app is in background android kill it to access more ram.

You can read more about application kill at How to create a persistent AlarmManager, and How to save Alarm after app killing?

Upvotes: 0

Related Questions