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.
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:
Intent
(matches via filterEquals()
, which pretty much means it matches on everything except the extras)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.