Search code examples
android-alarms

Confuse with this time format in Android AlarmManager


I am very confuse with these time format :

 alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), (24 * 60 * 60 * 1000), alarmIntent);

or

alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60*1000, alarmIntent);

What is 60*1000 and (10 * 1000), (24 * 60 * 60 * 1000). Can someone explain it to me?


Solution

  • Referring to the official documentation of AlarmManager API (found here), these numbers are used to define the time at which the alarm should be set off. So the numbers (10*1000) represent the time in milliseconds (or simply 10 secs) added to the current time of the system (again in milliseconds). So, the alarm in this case will be set off at 10 secs after the command is issued (current system time + 10 secs).

    The second parameter (24*60*60*1000) represents a time of 1 day (24 hours, 60 mins, 60 secs, and 1000 milliseconds in every sec). Since the complete expression is not specified, I can't tell the exact significance of this parameter.

    In the second expression also, 60*1000 represents 1 min (60 * 1000 = 60000 milliseconds = 1 min)

    Feel free to post any doubts that you still have about the meaning of these numbers.