setRepeating of AlarmManager not respond within the time indicated

后端 未结 1 1484
花落未央
花落未央 2021-01-27 05:42

AlarmManager should be repeated every 1 minute, but repeated every 1, 2, 3 or 4 minutes.

Since the application I throw AlarmManager

public class Paciente         


        
1条回答
  •  清歌不尽
    2021-01-27 06:13

    As of KitKat (API 19), alarms are inexacted and batched together to preserve battery life by minimizing the number of times the device needs to wake up.

    From the AlarmManager documentation for setRepeating():

    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 as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.

    For more precision you will need to use setExact() and reschedule an alarm every time an alarm wakes up your app. Do so very carefully though, as setting frequent alarms (such as every 1 minute) will dramatically decrease your users' battery life.

    From the setExact() documenation:

    Note: only alarms for which there is a strong demand for exact-time delivery (such as an alarm clock ringing at the requested time) should be scheduled as exact. Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS's ability to minimize battery use.

    0 讨论(0)
提交回复
热议问题