문제

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:

  • 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top