Android: how to get PendingIntent id to cancel pendingintent

I work with alarm manager. As soon as I set PendingIntentthe alarm to start, I want to cancel it.

How do I achieve this?

Help will be appreciated.

+4
source share
1 answer

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

The main thing you need:

  • Create a pending intent with the same identifier and corresponding FLAG planning.
  • Cancel this pending intention.
  • Cancel the alarm using the 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 !!

+4
source

All Articles