I have set multiple repeating alarms each with different PendingIntent. Is there a way to cancel all these alarms at once? The only way i find to cancel alarms is to create individual PendingIntent and then call AlarmManager.cancel(pendingIntent) method. As I have many different alarms with different PendingIntent i will have to recreate all those, is there a better way?
Asked
Active
Viewed 329 times
2 Answers
0
The only way you can do is recreate your pending intent and cancel it.
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent updateServiceIntent = new Intent(context, MyPendingIntentService.class);
PendingIntent pendingUpdateIntent = PendingIntent.getService(context, 0, updateServiceIntent, 0);
// Cancel it
try{
alarmManager.cancel(pendingUpdateIntent);
} catch (Exception e) {
Log.e(TAG, "Update failed " + e.getMessage());
}

Community
- 1
- 1

Anoop M Maddasseri
- 10,213
- 3
- 52
- 73