Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AlarmManager - RTC_WAKEUP vs 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.

Example code:

    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?

I appreciate your help.

like image 249
Camille Sévigny Avatar asked May 09 '11 14:05

Camille Sévigny


People also ask

What is Rtc_wakeup?

RTC_WAKEUP and ELAPSED_REALTIME_WAKEUP will wake up the device out of sleep mode. If your PendingIntent is a broadcast PendingIntent , Android will keep the device awake long enough for onReceive() to complete.

What is AlarmManager in Android?

android.app.AlarmManager. This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future.


1 Answers

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

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

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.

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); 

this, on the other hand, will trigger the alarm 30 seconds from now.

AlarmManager.ELAPSED_REALTIME_WAKEUP type is rarely used compared to AlarmManager.RTC_WAKEUP.

like image 192
Rejinderi Avatar answered Sep 23 '22 19:09

Rejinderi