0
## Cancel Pending Intents ##

 private void Alarm_off_Click(object sender, EventArgs e)
    {
        OnAlaramStop();
    }
    public void OnAlaramStop()
    {
         Intent myint = new Intent();
        PendingIntent pendingIntent = 
        PendingIntent.GetBroadcast(Application.Context, 0, myint, 
        PendingIntentFlags.CancelCurrent);
        alarm_manager.Cancel(pendingIntent);

    }

I create multiple Pending Intents, that wake-up my device at specific time, but i wants that , when i click the Alaram_Off Button , then all the pending Intents Cancel. But Unfortunately pending Intents are not cancelled. Who will help me, Thanks in advance all my dears.

1 Answers1

1

Please don't use OnDestroy to name your custom method, because it already exits in both Activity and Service. Just change OnDestory to OnAlaramStop, like this:

public void OnAlaramStop()
{
    alarm_manager.Cancel(pendingIntent);
    pendingIntent.Cancel();

}
Robbit
  • 4,300
  • 1
  • 13
  • 29
  • [Please refer to this](https://stackoverflow.com/questions/14485368/delete-alarm-from-alarmmanager-using-cancel-android), you need use [PendingIntentFlags](https://developer.xamarin.com/api/type/Android.App.PendingIntentFlags/) – Robbit Jan 22 '18 at 11:37
  • Sir , PendingIntentFlags.UpdateCurrent is working here, but actually i want to Cancel Completely all the Pending Intents, So i change my Code as above ,but not working still,i don't know ??????? – Abdul Jalil Marwat Jan 23 '18 at 17:02
  • Above your code, add `pendingIntent.Cancel();` in your `OnAlaramStop()` method. Did you forgot it? – Robbit Jan 24 '18 at 14:19
  • I change the Intent as above, and start work perfect for me , thank you very much – Abdul Jalil Marwat Feb 17 '18 at 14:05