Question

Simple question: is the AlarmManager always cleared after reboot? Is it cleared after reboot on all devices and even when the user boots his device up very shortly after he booted it off?

I need to know this because I recreate my app's alarm in an OnBootReceiver and I want to avoid having double alarms set.

Was it helpful?

Solution

is the AlarmManager always cleared after reboot?

Definitely on a full reboot. There are some devices that have a "quickboot" (HTC comes to mind), and I have not run experiments to see what the behavior is there.

and even when the user boots his device up very shortly after he booted it off?

Yes.

I need to know this because I recreate my app's alarm in an OnBootReceiver and I want to avoid having double alarms set.

Alarms are effectively in a HashMap keyed by PendingIntent. Setting an alarm using an equivalent PendingIntent should replace the prior alarm. By "equivalent", I mean:

  • Same operation (activity, service, broadcast)
  • Same request code
  • Equivalent Intent (matches via filterEquals(), which pretty much means it matches on everything except the extras)
  • And I'd be nervous about using FLAG_CANCEL_CURRENT when defining the new PendingIntent

You can use adb shell dumpsys alarm to confirm what alarms are set, so you are sure that you wind up with the right number of alarms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top