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:

  • how to include custom title view with in AlertDialog in android?
  • Google Tag Manager throws “invalid macro” message
  • add back button to action bar
  • Create Email account from type existing Account Services
  • Parse with Facebook login - Possibly since APK v42 or Graph API v2.4
  • Setting Android images from string value
  •     alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 

    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.

    Related posts:

    File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
    Provide custom text for Android M permission dialog
    Error while trying to create circular reveal: IllegalStateException: cannot start this animation on ...
    How to get Bitmap from an Uri?
    How to measure height, width and distance of object using camera?
    Android signature verification
  • Android 8 or higher: Check for Google Play Services
  • Delay in streaming audio
  • Twitter Authentication through Android's AccountManager classes
  • Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup
  • Run only one custom app in Android, prevent anything else from running
  • Android WebView Javascript from assets
  • 5 Solutions collect form web for “Android AlarmManager – RTC_WAKEUP vs 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);

    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.

    Despite the currently accepted and up-voted answer, AlarmManager.ELAPSED_REALTIME* types along with SystemClock.elapsedRealtime() has always been more reliable than the RTC clocks for alarms and timing.

    Using ELAPSED_REALTIME_WAKEUP with AlarmManager will rely on a monotonic clock starting from boot time “and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing“. So,

    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()
                     + 60*1000, pendingIntent);

    will make your PendingIntent fire in 1 min (60*1000 milliseconds).

    Whereas, AlarmManager.RTC_WAKEUP is for the the standard “wall” time in milliseconds since the epoch. So,

    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                     + 60*10000, pendingIntent);

    may also trigger the alarm 60 seconds from now, but not reliably, because as noted in the SystemClock documentation:

    The wall clock can be set by the user or the phone network (see
    setCurrentTimeMillis(long)), so the time may jump backwards or
    forwards unpredictably. This clock should only be used when
    correspondence with real-world dates and times is important, such as
    in a calendar or alarm clock application. Interval or elapsed time
    measurements should use a different clock. If you are using
    System.currentTimeMillis(), consider listening to the
    Intent broadcasts to find out when the time changes.

    Also, the question only referenced only the *_WAKEUP alarms but see also the AlarmManager documentation on that to make sure you understand what the wakeup vs non-wakeup alarms provide.

    Just a note. You can get the uptime millis calling:

    long uptimeMillis =  SystemClock.elapsedRealtime();

    So if you want to fire the alarm 30 seconds from now, and you want to use the uptime clock instead of the normal clock, you can do:

    long thirtySecondsFromNow =  SystemClock.elapsedRealtime() + 30 * 1000;
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, thirtySecondsFromNow, pendingIntent);

    Whenever you want to check for some elapsed time instead of a specific date/time, it’s best to use the uptime. That’s because the current time set by the user in the device can change if the user changes it using the settings.

    I programmed this problem in my own project this way. in below code i am using


    to set alarm at a specific time.
    the variable ‘intentName’ is used in the intentFilter to receiver this alarm. because i am firing many alarms of this type. when i cancel all alarms. i use the method cancel. given at bottom.

    //to hold alarms and cancel when needed

         public static ArrayList<String> alarmIntens = new ArrayList<String>();


        public static String setAlarm(int hour, int minutes, long repeatInterval,
            final Context c) {
         * to use elapsed realTime monotonic clock, and fire alarm at a specific time
         * we need to know the span between current time and the time of alarm.
         * then we can add this span to 'elapsedRealTime' to fire the alarm at that time
         * this way we can get alarms even when device is in sleep mood
        Time nowTime = new Time();
        Time startTime = new Time(nowTime);
        startTime.hour = hour;
        startTime.minute = minutes;
        //get the span from current time to alarm time 'startTime'
        long spanToStart = TimeUtils.spanInMillis(nowTime, startTime);
        intentName = "AlarmBroadcast_" + nowTime.toString();
        Intent intent = new Intent(intentName);
        PendingIntent pi = PendingIntent.getBroadcast(c, alarms++, intent,
        AlarmManager am = (AlarmManager) c
        //adding span to elapsedRealTime
        long elapsedRealTime = SystemClock.elapsedRealtime();
        Time t1 = new Time();
        t1.second=0;//cut inexact timings, seconds etc
        elapsedRealTime = t1.toMillis(true);
        if (!(repeatInterval == -1))
                    elapsedRealTime + spanToStart, repeatInterval, pi);
            am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, elapsedRealTime
                    + spanToStart, pi);

    where span function is this:

     public static long spanInMillis(Time startTime, Time endTime) {
        long diff = endTime.toMillis(true) - startTime.toMillis(true);
        if (diff >= 0)
            return diff;
            return AlarmManager.INTERVAL_DAY - Math.abs(diff);

    alarm cancel function is this.

    public static void cancel(Context c) {
        AlarmManager am = (AlarmManager) c
        // cancel all alarms
        for (Iterator<String> iterator = alarmIntens.iterator(); iterator
                .hasNext();) {
            String intentName = (String);
            // cancel
            Intent intent = new Intent(intentName);
            PendingIntent pi = PendingIntent.getBroadcast(c, 0, intent,

    Some important notes when choosing which alarm to use:(for whom who already read the upvoted votes)

    The RTC_WAKEUP death valley – time change:
    If the user has manually change time to the past the alarm won’t go off, and future will cause the alarm to go off immediately if it past the RTC timestamp.
    Do not use this alarm to do any client side verification / important jobs because it have a chance to fail.

    The WAKEUP meaning (Marshmallow and above)
    In general – not much. Will not wakeup the device when idle or while in doze, for that alarmManager.setExactAndAllowWhileIdle or alarmManager.setAndAllowWhileIdle (Doze & Idle)

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.