通过设定一个AlarmManager不精确报警时,有多少延迟呢? [英] How much delay is there when setting an inexact alarm via AlarmManager?

查看:787
本文介绍了通过设定一个AlarmManager不精确报警时,有多少延迟呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 AlarmManager 来设置闹铃,有可能是在该警报被触发一段时间在指定时间后,除非你设定一个确切的报警延迟。是否有什么这个延时的范围可以是任何保证?我想成为一个负责任的开发商,如果延迟不超过,比如说,一分钟以上不使用确切的时间。但我不能找到文档中的延迟任何规格。我想AP preciate该文献的资源如何延迟功能,它的时间规范。


解决方案

  

75%的任一重复间隔[用于周期性报警]或之时从现在到所需的交付时间,以10秒的最小延迟/时间间隔,根据该我们将简单地不推迟报警。


从Android源<一个href=\"http://androidxref.com/4.4_r1/xref/frameworks/base/services/java/com/android/server/AlarmManagerService.java#maxTriggerTime\"相对=nofollow> AlarmManagerService 为API19(现在仍然一样API23的)


   请求批处理窗口
     1分钟] - > 1 1.75分钟]
    10分钟 - >10-17½分钟]
    30分钟 - >30-52½分钟]
     1小时 - > 1小时1.75

另外值得一提的是,虽然AlarmManagerService守卫窗口长度,确保长度超过半天被视为怀疑(和改写为1小时)时,它不会触发时间提供类似的完整性检查。

因此​​,你可以很容易地提供一个基于RTC值(System.currentTimeMillis的())与基于经过模式(ELAPSED_REALTIME),并与报警这是千百年来在将来结束。

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.

解决方案

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.

这篇关于通过设定一个AlarmManager不精确报警时,有多少延迟呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆