Archana
Archana

Reputation: 43

How to get PendingIntent id for canceling pendingintent

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?

Upvotes: 3

Views: 2866

Answers (1)

Rahul Baradia
Rahul Baradia

Reputation: 11951

These following code will 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.

Code:

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

Upvotes: 4

Related Questions