4

In my app, I would like to delete all pendingIntent in my alarmManager. Is possible to do a for() to delete all?

535441434B
  • 273
  • 1
  • 18
Anto
  • 907
  • 5
  • 14
  • 26

3 Answers3

2

Try this.

Android: Get all PendingIntents set with AlarmManager

To cancel all alarm, first you have to find all the pending intent for that and cancel alarm using that.

If it is helpful to you than don't miss to accept this as your answer.

Community
  • 1
  • 1
Solution
  • 604
  • 4
  • 10
2
// set up alarm 
List<PendingIntent> mPendingIntentList = new ArrayList<PendingIntent>();
Intent alarmIntent = new Intent(getApplicationContext(),Receiver.class);
alarmIntent.setData(Uri.parse("custom://" + alarm.ID));
alarmIntent.setAction(String.valueOf(alarm.ID));
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

PendingIntent displayIntent = PendingIntent.getBroadcast(getContext(), 0,                  alarmIntent, 0);

// add pending intent in list
mPendingIntentList.add(displayIntent );
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmDateTime, displayIntent);



    //cancel all alarms
    for(int idx = 0 ; idx < mPendingIntentList.size() ; idx++){
       alarmManager .cancel(mPendingIntentList.get(idx));
    }
Anurag Aggarwal
  • 247
  • 1
  • 5
-2

See AlarmManager.cancel(PendingIntent)

Create a PendingIntent matching the intent(s) you wish to cancel. Calling the above function once, will cancel all matching alarms .

CompEng88
  • 1,336
  • 14
  • 25