Skip to content Skip to sidebar Skip to footer

How To Cancel Alarm Programmatically In Android?

I used this code to create an alarm and it works. Please suggest how to cancel that alarm. Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM); alarmIntent.s

Solution 1:

You need to use the method cancel(...) from AlarmManager, using the same PendingIntent you used to set the alarm. Example:

this.getAlarmManager().cancel(mAlarmPendingIntent); (this refers to the Activity or the Service from which you are cancelling the alarm).

Create the PendingIntent as:

mAlarmPendingIntent = PendingIntent.getActivity(this, requestCode, intent, flags);

Solution 2:

You have to invoke the cancel method: link

The PendingIntent should be same that you have set before with AlarmManager.

Post a Comment for "How To Cancel Alarm Programmatically In Android?"