0

Hi I'm trying to cancel AlarmManager. I wrote some test code but It,s not working, my code:

Alarm creation:

            Intent myIntent = new Intent(this,NotificationService.class);
            PendingIntent pendingIntentFriday = PendingIntent.getService(this,123098,myIntent, PendingIntent.FLAG_CANCEL_CURRENT);

            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);         
            alarmManager.set(AlarmManager.RTC_WAKEUP,nextFriday.getTimeInMillis() , pendingIntentFriday);

Alarm cancel:

            Intent stopIntent = new Intent(this,NotificationService.class);
            PendingIntent stopFriday = PendingIntent.getService(this,123098,stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            AlarmManager stopManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            stopManager.cancel(stopFriday);
Omarj
  • 1,151
  • 2
  • 16
  • 43
user691285
  • 401
  • 1
  • 6
  • 17

2 Answers2

0

Try changing your flag to "FLAG_UPDATE_CURRENT"

jbrulmans
  • 975
  • 1
  • 11
  • 32
-3
 AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
 Intent intent = new Intent(context, ReceiverForCancelling.class);
  PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent,
  PendingIntent.FLAG_CANCEL_CURRENT);
   service.cancel(pending)
vmb
  • 2,878
  • 15
  • 60
  • 90