4

I have been working with an alarm manager. Once I set a PendingIntent for triggering the alarm, I want to cancel it.

How do I achieve this?

Help will be appreciated.

Rahul Baradia
  • 11,749
  • 16
  • 74
  • 121
Archana
  • 45
  • 1
  • 7
  • check http://stackoverflow.com/questions/3330522/how-to-cancel-this-repeating-alarm and http://stackoverflow.com/questions/4212824/identify-and-cancel-an-alarm-send-to-an-alarmmanager – Jaiprakash Soni Jul 03 '15 at 10:42

1 Answers1

4

These following lines of code surely can help you remove/cancel the pending intent and alarm.

The main thing that you will need is:

  • Create pending intent with the same id and appropriate intent FLAG.
  • Cancel that pending intent.
  • Cancel the alarm using alarm manager.

    Intent myIntent = new Intent(PresentActivity.this, AlarmActivity.class);          
    pendingIntent = PendingIntent.getActivity(PresentActivity.this,pending_intent_unique_id, myIntent,PendingIntent.FLAG_UPDATE_CURRENT);
    pendingIntent.cancel();
    alarmManager.cancel(pendingIntent);
    

Happy Coding !!

Rahul Baradia
  • 11,749
  • 16
  • 74
  • 121
  • Is there a way to get the running pendingintents? I need to update the timer clock based on the time left for the alarm, after the app was closed and reopened. – Dpedrinha Aug 29 '17 at 21:30