Search code examples
androidalarmmanagerandroid-notifications

Meaning of AlarmManager parameters


To set an alarm, I use

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureTimeInMillis, pendingIntent);

I don't understand the relation between AlarmManager.ELAPSED_REALTIME_WAKEUP and futureTimeInMillis. For example, say I want an alarm to go off 15 minutes from now. Then what is the value of futureTimeInMillis? is it

futureTimeInMillis = NOW+MIN_15;

or is it

    futureTimeInMillis = MIN_15;

Solution

  • According to the doc AlarmManager.ELAPSED_REALTIME_WAKEUP:

    Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.

    So it does not what that you actually want, i guess.

    As for your question, AlarmManager.RTC_WAKEUP should be used for that with

    futureTimeInMillis = NOW+MIN_15