Android AlarmManager - RTC_WAKEUP 与 ELAPSED_REALTIME_WAKEUP [英] Android AlarmManager - RTC_WAKEUP vs ELAPSED_REALTIME_WAKEUP

查看:72
本文介绍了Android AlarmManager - RTC_WAKEUP 与 ELAPSED_REALTIME_WAKEUP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释 AlarmManager.RTC_WAKEUPAlarmManager.ELAPSED_REALTIME_WAKEUP 之间的区别吗?我已经阅读了文档,但仍然没有真正理解使用一个而不是另一个的含义.

Can someone explain to me the difference between AlarmManager.RTC_WAKEUP and AlarmManager.ELAPSED_REALTIME_WAKEUP? I have read the documentation but still don't really understand the implication of using one over the other.

示例代码:

    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
                     scheduledAlarmTime, 
                     pendingIntent);

    alarmManager.set(AlarmManager.RTC_WAKEUP, 
                     scheduledAlarmTime, 
                     pendingIntent);

这两行代码的执行会有什么不同?这两行代码什么时候相对执行?

How different will the two lines of code execute? When will those two lines of code execute relative to each other?

感谢您的帮助.

推荐答案

AlarmManager.ELAPSED_REALTIME_WAKEUP 类型用于触发开机以来的报警:

AlarmManager.ELAPSED_REALTIME_WAKEUP type is used to trigger the alarm since boot time:

alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 600000, pendingIntent);

实际上会在设备启动 10 分钟后关闭闹钟.

will actually make the alarm go off 10 min after the device boots.

有一个计时器在设备启动时开始运行以测量设备的正常运行时间,这是根据设备的正常运行时间触发警报的类型.

There is a timer that starts running when the device boots up to measure the uptime of the device and this is the type that triggers your alarm according to the uptime of the device.

AlarmManager.RTC_WAKEUP会根据时钟的时间触发闹钟.例如,如果您这样做:

Whereas, AlarmManager.RTC_WAKEUP will trigger the alarm according to the time of the clock. For example if you do:

long thirtySecondsFromNow = System.currentTimeMillis() + 30 * 1000;
alarmManager.set(AlarmManager.RTC_WAKEUP, thirtySecondsFromNow , pendingIntent);

另一方面,这将在 30 秒后触发警报.

AlarmManager.ELAPSED_REALTIME_WAKEUP 类型很少使用.

这篇关于Android AlarmManager - RTC_WAKEUP 与 ELAPSED_REALTIME_WAKEUP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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