如何为此代码停止/取消特定的pendingintent?

时间:2017-04-20 06:54:15

标签: java android alarmmanager android-pendingintent

我正在安排多个意图发送到BroadcastReceiver。每个意图之间的区别在于它将被接收的时间和它包含的额外数据 现在我需要取消特定的待定意图。

这是SetAlarm()方法的代码:

int mrng_hour = Integer.parseInt(ls.get(i).getSch_mrng_hour());
int mrng_mins = Integer.parseInt(ls.get(i).getSch_mrng_mins());
Calendar mrng_calendar = Calendar.getInstance();
mrng_calendar.set(Calendar.HOUR_OF_DAY, mrng_hour);
mrng_calendar.set(Calendar.MINUTE, mrng_mins);
mrng_calendar.set(Calendar.SECOND, 0);
Intent in = new Intent(context, Alarmclass.class); in .putExtra("mid", req_CODE);
PendingIntent mrng_pi = PendingIntent.getService(context, req_CODE, in , PendingIntent.FLAG_UPDATE_CURRENT);
mgrAlarm.setRepeating(AlarmManager.RTC_WAKEUP, mrng_calendar.getTimeInMillis(),
    AlarmManager.INTERVAL_DAY, mrng_pi);

1 个答案:

答案 0 :(得分:0)

您需要再次创建相同的pendingintent并取消它。 alarmManager.cancel(pendingIntent);