Run code every day at a specific time - AlarmManager

前端 未结 2 783
清歌不尽
清歌不尽 2021-01-25 04:29

Currently, I am trying to run a piece of code at a specific time. After some research, I think the correct way to go is to make usage of the AlarmManger. The code s

2条回答
  •  孤街浪徒
    2021-01-25 05:06

    Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time.

    Inexact scheduling means the time between any two successive firings of the alarm may vary. Thats what happening in your case i guess.To overcome the exact time issue i think you should use one shot alarm.But in this case you need to reschedule it for next day. and so on. You can get a very clear understanding from the Documentation setrepeating , setInexactRepeating.

    EDIT:- TO optimizing DOZE mode In Case you are Using setAndAllowWhileIdle() or setExactAndAllowWhileIdle(), Then you must read This Document which says :-

    Neither setAndAllowWhileIdle() nor setExactAndAllowWhileIdle() can fire alarms more than once per 9 minutes, per app.

提交回复
热议问题