Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 610
Castaldi Avatar asked Aug 29 '14 10:08

Castaldi


2 Answers

From documentation, if the startDate time is in the past, the alarm will be triggered immediately.

like image 117
Xavier Egea Avatar answered Oct 01 '22 18:10

Xavier Egea


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.

like image 30
Rahul Tripathi Avatar answered Oct 01 '22 19:10

Rahul Tripathi