[英]Is alarmmanager ALWAYS cleared after reboot?
Simple question: is the AlarmManager
always cleared after reboot? 一个简单的问题:重新启动后AlarmManager
总是清除AlarmManager
? 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. 我需要知道这一点,因为我在OnBootReceiver
重新创建了应用程序的警报,并且希望避免设置双重警报。
is the AlarmManager always cleared after reboot? 重新启动后总是清除AlarmManager吗?
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. 有些设备具有“快速启动”功能(我想到了HTC),而我还没有进行实验来了解其行为。
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. 我需要知道这一点,因为我在OnBootReceiver中重新创建了应用程序的警报,并且希望避免设置双重警报。
Alarms are effectively in a HashMap
keyed by PendingIntent
. 警报有效地存在于由PendingIntent
键控的HashMap
。 Setting an alarm using an equivalent PendingIntent
should replace the prior alarm. 使用等效的PendingIntent
设置警报应替换先前的警报。 By "equivalent", I mean: “等同”是指:
Intent
(matches via filterEquals()
, which pretty much means it matches on everything except the extras) 等效Intent
(通过filterEquals()
匹配,这几乎意味着它与其他所有filterEquals()
都匹配) FLAG_CANCEL_CURRENT
when defining the new PendingIntent
而且我在定义新的PendingIntent
时会担心使用FLAG_CANCEL_CURRENT
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. 您可以使用adb shell dumpsys alarm
来确认设置了哪些警报,因此可以确保以正确数量的警报结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.