经理。取消(挂起意图)在 Xamarin Android 中对我不起作用


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

我创建了多个待处理的意图,在特定时间唤醒我的设备,但我希望,当我单击Alaram_Off按钮时,所有挂起的意图都会取消。但不幸的是,待定的意图并没有被取消。谁会帮助我,提前感谢我所有的亲爱的。

请不要使用OnDestroy来命名您的自定义方法,因为它已经在ActivityService中退出。只需将OnDestory更改为OnAlaramStop,如下所示:

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

相关内容

最新更新