您好我使用alarmManager
每3分钟触发一次警报。所以我使用setRepeating
方法来警报每3分钟触发一次。这适用于某些设备。但是当它进入睡眠模式然后打开时,警报不起作用。
public void startAt3() {
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
/* Set the alarm */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
/* Repeating on every 3 minute interval */
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 60 * 3, pendingIntent);
}
我读到它在Android 6.0中进入打盹模式。那么哪个适合使用而不是setRepeating
方法呢?
答案 0 :(得分:0)
setExact - 用于设置在指定时间准确传送的闹钟。
setInexactRepeating - 用于设置警报的某个预定义时间间隔。这比restore()
好吗?与其他方法相比,这种方法消耗更少的资源,更少的电池。因此,建议尽可能使用setRepeating()
。 Android将在运行时同步多个不准确的警报以节省资源。以下是精确重复的可能值; (在api等级19之前)
setInexactRepeating()
setRepeating - 用于将警报的确切时间设置为毫秒。我们真的要用这个吗?由于此方法消耗更多资源,因此除非确实有必要,否则没有人会推荐这种方法。