AlarmManager alarm is called immediately when trigger time is in the past

后端 未结 2 1862
旧巷少年郎
旧巷少年郎 2021-01-29 08:01

Below is the code I am using to create alarms when data is pulled from external API. If the time set is in the past, the alarm goes off as soon as it is set(2 second gap). For e

2条回答
  •  甜味超标
    2021-01-29 08:35

    This is the expected behavior.

    From the documentation of setRepeating() (and other AlarmManager set methods):

    If the stated trigger time is in the past, the alarm will be triggered immediately

    If you would like to prevent that happening, then simply do not set alarms with a past trigger time (e.g. check against System.currentTimeMillis() when setting the alarm).

提交回复
热议问题