Android installation alarm for a past date

What happens if I have to add an alarm but set the start date to the last date?

Is it running immediately, or is it queued and never executed?

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startDate, repeatingValue, alarmIntent); 
+6
source share
7 answers

If the date is in the past, then the alarm will start immediately. However, you can try using setInexactRepeating instead of setRepeating :

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

From setInexactRepeating () docs :

Schedule a recurring alarm that has inaccurate start time requirements; for example, an alarm clock that repeats every hour, but not necessarily the top of every hour.

+5
source

From the documentation , if the startDate time has passed, the alarm will immediately start.

+7
source

In fact, AlarmManager works with the current time. Therefore, when you set the past date alarm, AlarmManager will execute

 public void onReceive(Context context, Intent intent) { } 

method.

+1
source

I think that the alarm is set only on the clock (at least through the Android user interface), and not on a specific day, so it will start with the exact hour:minute that you set.

0
source

As I can conclude from my previous experience with AlarmManager . A date that was in the past immediately gives an alarm.

0
source

As far as I can tell, AlarmManager.set will be executed now, when the time is set last time, the documentation says the same. This offer is absent for AlarmManager.setInexactRepeating, this signal will not work, if it has been set in the last time, it will be triggered at the next interval, starting from the specified time.

0
source

AlarmManager.set and AlarmManager.setInexactRepeating are both callers of setImpl, with the trigger they received as a parameter (tested in Android 7.1.2 sources). -> There is no difference in both methods if the trigger is in the past.

0
source

Source: https://habr.com/ru/post/974541/


All Articles