Archana Archana - 1 year ago 143
Android Question

Android : How to get PendingIntent id for canceling pendingintent

I have been working with an

alarm manager
. Once I set a
for triggering the alarm, I want to cancel it.

How do I achieve this?

Help will be appreciated.

Answer Source

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);

Happy Coding !!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download