触发后取消待处理意图/警报

时间:2016-01-05 10:19:20

标签: android android-notifications android-pendingintent android-alarms

我使用以下代码创建通知,但在通知被触发后,当我检查是否有警报时,它仍处于打开状态。一旦被解雇,它是否应该从系统中禁用?我怎么处理这个?

Intent myIntent = new Intent(this, NotifyCallService.class);
myIntent.putExtra("lastName", lastName);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 11, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);

alarmManager.set(AlarmManager.RTC_WAKEUP, startTime, pendingIntent);

我用以下代码检查闹钟:

Intent myIntent = new Intent(getActivity(), NotifyCallService.class);
boolean alarmUp = (PendingIntent.getService(getActivity(), 11, myIntent, PendingIntent.FLAG_NO_CREATE) != null);

1 个答案:

答案 0 :(得分:1)

pendingIntent仍在,但不一定是你的警报。如果要确保警报处于非活动状态,请致电alarmManager.cancel()