AlarmManager.setAndAllowWhileIdle()
和 AlarmManager.setExactAndAllowWhileIdle()
有什么区别?这两者如何影响 Android 6.0 (Marshmallow) API 中引入的打盹模式?
最佳答案
引用AlarmManager
的文档:
Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.
事实上,您提到的两种方法都指定它们的行为与没有“AndAllowWhileIdle”(set
和 setExact
)的对应方法一样。因此,其中一个会在准确的时间发出警报,而另一个则不准确。
关于android - setAndAllowWhileIdle 和 setExactAndAllowWhileIdle 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35666127/