Android Alarm AlarmManager 提供的四种 Alarm 有什么区别以及何时使用什么?
我想知道RTC、RTC_WAKEUP、ELAPSED_REALTIME、ELAPSED_REALTIME_WAKEUP之间的区别。
我想编写一个闹钟应用程序,我将在其中设置闹钟并关闭我的应用程序,并期望在设置的时间发出闹钟。
会有多个警报。现在我正在为模拟器编写,但稍后将在设备上进行测试。在模拟器中,一旦我设置闹钟并关闭模拟器并重新启动它,它就会被清除,就像我在 RTC、RTC_WAKEUP 和 ELAPSED_REALTIME 中发现的那样。我很困惑。我应该使用 ELAPSED_REALTIME_WAKEUP 吗?我还没有看到任何使用 ELAPSED_REALTIME_WAKEUP 的教程。 请解释一下。 谢谢。
I want to know the difference between RTC, RTC_WAKEUP, ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP.
I want to write an alarm application where I will set alarm and close my application and expect for alarm for the time set.
There will be multiple alarms. Right now I am writing for emulator but later will test on device. In emulator, once I set the alarm and close the emulator and restart it, then will it be cleared, as I find with RTC, RTC_WAKEUP and ELAPSED_REALTIME. I am confused. Should I used ELAPSED_REALTIME_WAKEUP? I have not seen any tutorial using ELAPSED_REALTIME_WAKEUP.
please explain.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ELAPSED_REALTIME
SystemClock.elapsedRealtime() 中的闹钟时间(自启动以来的时间,包括睡眠)。该闹钟不会唤醒设备;如果它在设备睡眠时熄灭,则直到设备下次唤醒时才会传递。
ELAPSED_REALTIME_WAKEUP
SystemClock.elapsedRealtime() 中的闹钟时间(自启动以来的时间,包括睡眠),该时间会在设备关闭时唤醒设备。
System.currentTimeMillis() 中的RTC
闹钟时间(UTC 中的挂钟时间)。该闹钟不会唤醒设备;如果它在设备睡眠时熄灭,则直到设备下次唤醒时才会传递。
RTC_WAKEUP
System.currentTimeMillis() 中的闹钟时间(UTC 中的挂钟时间),当闹钟响起时会唤醒设备。
ELAPSED_REALTIME
Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.
ELAPSED_REALTIME_WAKEUP
Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.
RTC
Alarm time in System.currentTimeMillis() (wall clock time in UTC). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.
RTC_WAKEUP
Alarm time in System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off.
警报类型:
Types of Alarms :
闹钟有两种通用时钟类型:“经过的实时”和“实时时钟”(RTC)。经过的实时时间使用“系统启动以来的时间”作为参考,实时时钟使用 UTC(挂钟)时间。这意味着经过的实时时间适合根据时间的流逝设置警报(例如,每 30 秒触发一次警报),因为它不受时区/区域设置的影响。实时时钟类型更适合依赖于当前区域设置的警报。
来源:https://developer.android.com/training/scheduling/alarms.html< /a>
There are two general clock types for alarms: "elapsed real time" and "real time clock" (RTC). Elapsed real time uses the "time since system boot" as a reference, and real time clock uses UTC (wall clock) time. This means that elapsed real time is suited to setting an alarm based on the passage of time (for example, an alarm that fires every 30 seconds) since it isn't affected by time zone/locale. The real time clock type is better suited for alarms that are dependent on current locale.
Source: https://developer.android.com/training/scheduling/alarms.html
从该网站您可以得到 4 个常数之间的差异
以下是设置闹钟的示例
希望对您有所帮助
From the site you can get the difference between the 4 constanst
Below is example of the setting alarm
Hope this will be helpful to you