[問題] 關閉AlarmManager

看板AndroidDev作者 (Jimmy)時間7年前 (2017/07/02 22:55), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
各位好,我在我的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
Cancel兩個pendingIntent嗎
07/03 01:50, 1F

07/03 11:36, , 2F
是的~但目前看起來他只關閉了一個
07/03 11:36, 2F
文章代碼(AID): #1PMGbxSC (AndroidDev)
文章代碼(AID): #1PMGbxSC (AndroidDev)