Monday, 2 February 2015

How to Cancel an Alarm in Android ?

Cancelling a Repeating Alarm :

public void cancelRepeatingAlarm()
      // Get an intent that was originally used to invoke TestReceiver class
      Intent intent = new Intent(this.mContext, TestReceiver.class);
      // To Cancel, extra is not necessary to be filled in
      // Intent.putExtra("message", "Repeating Alarm");
      PendingIntent pi = this.getDistinctPendingIntent(intent, 2);

      // Cancel the alarm !
      AlarmManager am =    


* To cancel an alarm, we have to construct a pending intent first and then pass it to the alarm manager as an argument to the cancel () method.

No comments:

Post a Comment