作者pig98520 (Jimmy)
看板AndroidDev
标题[问题] 关闭AlarmManager
时间Sun Jul 2 22:55:52 2017
各位好,我在我的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://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1499007355.A.70C.html
1F:推 benntqoo: Cancel两个pendingIntent吗 07/03 01:50
2F:→ pig98520: 是的~但目前看起来他只关闭了一个 07/03 11:36