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

查看:49
本文介绍了AlarmManager 的 setRepeating 和 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 将每十五分钟恰好安排第一个闹钟;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.

请注意,这在 API 19 中发生了变化,这两个调用是同义词.请参阅本指南这个 API 文档.

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

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

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