0

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?

dlohani
  • 2,511
  • 16
  • 21

2 Answers2

0

As far as I know there is no other way to cancel the alarms

Varun Kumar
  • 1,241
  • 1
  • 9
  • 18
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());
     }

Courtsey

Community
  • 1
  • 1
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73