setRepeating AlarmManager和setInexactRepeating的区别 [英] Difference between setRepeating and setInexactRepeating of AlarmManager

查看:2360
本文介绍了setRepeating AlarmManager和setInexactRepeating的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是下面的参数:

alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);

和以下的:

alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        AlarmManager.INTERVAL_DAY, alarmIntent);

有什么区别,以及如何在功能方面两个有什么不同?

What is the difference and also how are the two different in terms of functionality?

推荐答案

两个例子都安排一个重复报警,将发送给定的 alarmIntent 。在这两种情况下,在第一时间将其发送器即刻( calendar.getTimeInMillis()返回的当前的时间)。在这两种情况下,该设备将被唤醒,当报警需要发送(如显然由 AlarmManager.RTC_WAKEUP )。

Both examples schedule a repeating alarm that will send the given alarmIntent. On both cases, the first time it is sent will be immediate (calendar.getTimeInMillis() returns the current time). On both cases, the device will be woken up when the alarm needs to be sent (as evident by AlarmManager.RTC_WAKEUP).

有这些调用的两个差异。比较简单的一种是意图将被发送,每天的第二个电话每15分钟在第一次调用,和(你可以在第三个参数见)。更复杂的差异函数调用自身: setRepeating 将安排对于完全每15分钟第一次报警; setInexactRepeating 将安排第二次报警的每24小时,这意味着它可能会偏离该区间 - 与功耗更低的优势

There are two differences between these calls. The simpler one is that the intent will be sent every fifteen minutes on the first call, and every day on the second call (as you can see in the third parameter). The more complicated difference is the function call itself: setRepeating will schedule the first alarm for exactly every fifteen minutes; setInexactRepeating will schedule the second alarm for approximately every 24 hours, meaning it might deviate from that interval - with the advantage of consuming less power.

请注意,这已经在19 API,在这两个电话是同义的改变。请参见本指南和的这个API文档

Do notice that this has changed in API 19, where these two calls are synonymous. See this guide, and this API documentation.

这篇关于setRepeating AlarmManager和setInexactRepeating的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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