Castaldi Castaldi - 1 year ago 92
Android Question

Android setting alarm to a past date

What happens should I add an alarm but set the starting date to a past date?

Does is get executed immediately or is it put in the queue and never executed?

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startDate, repeatingValue, alarmIntent);

Answer Source

If the date is in past then alarm will trigger immediately. However you may try to use setInexactRepeating instead of setRepeating:

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startDate, setInexactRepeating , alarmIntent);

From the setInexactRepeating() docs:

Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download