What happens to undelivered AlarmManager repeating alarms when phone wakes up?

﹥>﹥吖頭↗ 提交于 2019-12-10 14:49:09

问题


If we schedule an inexact repeating alarm with AlarmManager.setInexactRepeating to be fired every hour, for example, what happens if the phone is in standby for 4 hours and then it is woken up? Does the system deliver 4 alarms in a row for the same PendingIntent or does it deliver only a single alarm?

EDIT: reading the documentation with more attention, the set(int, long, android.app.PendingIntent) method documentation says: Alarm intents are delivered with a data extra of type int called Intent.EXTRA_ALARM_COUNT that indicates how many past alarm events have been accumulated into this intent broadcast. Recurring alarms that have gone undelivered because the phone was asleep may have a count greater than one when delivered. So, when the phone comes out of standby, only one alarm will be delivered, with an intent extra that contains the number of missed alarms.


回答1:


Reading the documentation with more attention, the set(int, long, android.app.PendingIntent) method documentation says: Alarm intents are delivered with a data extra of type int called Intent.EXTRA_ALARM_COUNT that indicates how many past alarm events have been accumulated into this intent broadcast. Recurring alarms that have gone undelivered because the phone was asleep may have a count greater than one when delivered. So, when the phone comes out of standby, only one alarm will be delivered, with an intent extra that contains the number of missed alarms.




回答2:


it depends if you use pending intent like this

  PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
            PendingIntent.FLAG_CANCEL_CURRENT);

it wont trigger 4 times as it cancells the previous pending intent



来源:https://stackoverflow.com/questions/12140824/what-happens-to-undelivered-alarmmanager-repeating-alarms-when-phone-wakes-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!