Alarm manager triggered immediately

后端 未结 2 1522
死守一世寂寞
死守一世寂寞 2021-02-04 05:26

Hi I am currently working with AlarmManager. I have written a code given below. As per code the AlarmManager should be triggered after 10 Sec, but here in my code the alarm mana

2条回答
  •  执念已碎
    2021-02-04 06:00

    If you are creating PendingIntent of an alarm for past time it will be fired immediately. Example - Schedule alarm for today 8AM but executing code around 11AM will fire immediately.

    Solution:

    cal.add(Calendar.DATE, 1);
    
    long delay = 24 * 60 * 60 * 1000;
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), delay,pendingIntent);` 
    

    This will fire the event on next day at specified time (i.e 8AM);

提交回复
热议问题