在 BroadcastReceiver 类中,我有这段代码,但我不明白为什么第一次通知不运行。如果我删除 if 循环,alarmmanager 会完美运行。价值观也还可以(我有一个向我展示的祝酒词)。是“如果”问题吗?
CheckboxPreference = prefs.getBoolean("checkboxPref", true);
notify = prefs.getString("notify", "");
if (CheckboxPreference){
if (notify.equals("1")){
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, morningAlarm);
}
if (notify.equals("2")){
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, morningAlarm);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal3.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, eveningAlarm);
}
if (notify.equals("3")){
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, morningAlarm);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal2.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, middleAlarm);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal3.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, eveningAlarm);
}
}