[问题] 关闭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