[問題] 關閉AlarmManager
各位好,我在我的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
新手上路請多見諒,先謝謝各位了。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.230.231.138
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1499007355.A.70C.html
推
07/03 01:50, , 1F
07/03 01:50, 1F
→
07/03 11:36, , 2F
07/03 11:36, 2F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章