In my app, I would like to delete all pendingIntent in my alarmManager.
Is possible to do a for()
to delete all?
Asked
Active
Viewed 1.0k times
4

535441434B
- 273
- 1
- 18

Anto
- 907
- 5
- 14
- 26
3 Answers
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.
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
-
code commented . Please check now and let me know if there are any issues :) – Anurag Aggarwal Jan 05 '17 at 19:45
-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
-
5
-
2@Roel, you don't need to. You just need 1 pending intent matching your alarm and AlarmManager.clancel() will cancel all the ones that match. – CompEng88 Jan 05 '17 at 17:18