我有一个BroadcastReceiver
重新安排启动和时间变化等事件的警报.但是当时间超过警报的触发时间时(例如,当用户手动更改设置的时间时),AlarmManager
在我可以添加一天重新安排警报之前立即触发警报.我怎么能避免这个?
我目前正在使用set并添加方法Calendar
来安排警报.
for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek <= Calendar.SATURDAY; dayOfWeek++) { if (alarm.getRepeatingDay(dayOfWeek - 1) && dayOfWeek >= nowDay && !(dayOfWeek == nowDay && alarm.timeHour < nowHour) && !(dayOfWeek == nowDay && alarm.timeHour == nowHour && alarm.timeMinute <= nowMinute)) { calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); alarmSet = true; break; } } if (!alarmSet) { for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek <= Calendar.SATURDAY; dayOfWeek++) { if (alarm.getRepeatingDay(dayOfWeek - 1) && dayOfWeek <= nowDay) { calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); calendar.add(Calendar.WEEK_OF_YEAR, 1); break; } } }
它也在文档中说明:
如果指定的触发时间是过去的,则会立即触发警报.
如何改变这种行为?