我想知道RTC,RTC_WAKEUP,ELAPSED_REALTIME,ELAPSED_REALTIME_WAKEUP之间的区别.
我想编写一个警报应用程序,我将设置警报并关闭我的应用程序,并期望在设置的时间内发出警报.
会有多个警报.现在我正在为模拟器编写,但稍后将在设备上进行测试.在模拟器中,一旦我设置了警报并关闭模拟器并重新启动它,那么它将被清除,正如我在RTC,RTC_WAKEUP和ELAPSED_REALTIME中找到的那样.我很迷惑.我应该使用ELAPSED_REALTIME_WAKEUP吗?我还没有看到任何使用ELAPSED_REALTIME_WAKEUP的教程.请解释.谢谢.
小智 17
ELAPSED_REALTIME
SystemClock.elapsedRealtime()中的闹钟时间(自启动以来的时间,包括睡眠).此警报不会唤醒设备; 如果在设备处于睡眠状态时熄灭,则在下次设备唤醒时才会发送.
ELAPSED_REALTIME_WAKEUP
SystemClock.elapsedRealtime()中的报警时间(自启动以来的时间,包括睡眠),它将在设备关闭时唤醒设备.
RTC
System.currentTimeMillis()中的闹钟时间(以UTC为单位的挂钟时间).此警报不会唤醒设备; 如果在设备处于睡眠状态时熄灭,则在下次设备唤醒时才会发送.
RTC_WAKEUP
System.currentTimeMillis()中的闹钟时间(以UTC为单位的挂钟时间),它将在设备关闭时唤醒设备.
警报类型:
从网站上您可以得到 4 个常数之间的差异 下面是设置警报的示例
Calendar mCalendar = Calendar.getInstance();
mCalendar.add(Calendar.SECOND, 20);
Intent intent_Timer = new Intent(TimerEvents.this, AlarmReceiver.class);
intent_Timer.putExtra("alarm_message", "Drax Rules!!!");
// In reality, you would want to have a static variable for the request
// code instead of 192837
PendingIntent sender = PendingIntent.getBroadcast(this, 192837,
intent_Timer, PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), sender);
Run Code Online (Sandbox Code Playgroud)
希望这对您有帮助
| 归档时间: |
|
| 查看次数: |
11914 次 |
| 最近记录: |