[問題] 關閉AlarmManager

作者: pig98520 (CheinFeng)   2017-07-02 22:55:52
各位好,我在我的APP裡面建立了兩個AlarmManager,
這是我的程式碼:
@RequiresApi(api = Build.VERSION_CODES.N)
private void morning_alarm(Calendar calendarTime) {
intent = new Intent(Setting_Activity.this,
AlarmNotificationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
if(calendarTime.before(now)) {
calendarTime.add(Calendar.DATE, 1);
manager.setRepeating(AlarmManager.RTC_WAKEUP,
calendarTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
calendarTime.add(Calendar.DATE,-1);
}
else
manager.setRepeating(AlarmManager.RTC_WAKEUP,
calendarTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
private void evening_alarm(Calendar calendarTime) {
intent = new Intent(Setting_Activity.this,
AlarmNotificationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0);
if(calendarTime.before(now)) {
calendarTime.add(Calendar.DATE, 1);
manager.setRepeating(AlarmManager.RTC_WAKEUP,
calendarTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
calendarTime.add(Calendar.DATE,-1);
}
else
manager.setRepeating(AlarmManager.RTC_WAKEUP,
calendarTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
但後來我設了一個switch想要做關閉,當我的switch關閉時,
manager.cancel(pendingIntent),但似乎沒辦法同時關閉兩個,
想問一下該怎麼改寫比較好?
或是有其他辦法能夠同時關閉兩個AlarmManager
新手上路請多見諒,先謝謝各位了。
作者: benntqoo (This Letter)   2017-07-03 01:50:00
Cancel兩個pendingIntent嗎
作者: pig98520 (CheinFeng)   2017-07-03 11:36:00
是的~但目前看起來他只關閉了一個

Links booklink

Contact Us: admin [ a t ] ucptt.com