How much delay is there when setting an inexact alarm via AlarmManager? [duplicate]

房东的猫 提交于 2020-01-11 10:22:10

问题


When using AlarmManager to set an alarm, there could be a delay in which the alarm is triggered some time after the specified time unless you set an exact alarm. Is there any guarantee on what the range of this delay could be? I want to be a responsible developer and not use exact times if the delay is not more than, say, one minute. But I can't find any specifications on the delay in documentation. I would appreciate a resource that documents how the delay functions and its time specifications.


回答1:


75% of either the recurrence interval [for a periodic alarm] or of the time from now to the desired delivery time, with a minimum delay/interval of 10 seconds, under which we will simply not defer the alarm.

From the Android source for AlarmManagerService for API19 (and still the same as of API23)

   Requested    Batch Window
     1 Mins  ->  1- 1¾ Mins
    10 Mins  -> 10-17½ Mins
    30 Mins  -> 30-52½ Mins
     1 Hour  ->  1- 1¾ Hours

It's also worth noting that while AlarmManagerService guards the window length to ensure that lengths greater than half a day are treated as suspicions (and rewritten to 1 hour), it doesn't provide similar sanity checks for trigger times.

As a result you can easily provide an RTC based value (System.currentTimeMillis()) with an elapsed based mode (ELAPSED_REALTIME) and end up with an alarm that's thousands of years in the future.



来源:https://stackoverflow.com/questions/34409067/how-much-delay-is-there-when-setting-an-inexact-alarm-via-alarmmanager

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