问题
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