取消一个PendingIntent [英] Cancelling a PendingIntent

查看:154
本文介绍了取消一个PendingIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用在 AppWidgetProvider ,我用下面的code一个PendingIntent:

When using a PendingIntent in an AppWidgetProvider, I'm using the following code:

views.setOnClickPendingIntent( viewId,
                PendingIntent.getBroadcast( context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT ) );

所以目前没有参考保持的getBroadcast方法返回的PendingIntent。在特定情况下我现在要取消的PendingIntent。有什么办法获得PendingIntent从后面观的?或者是通过保持对它的引用调用PendingIntent的取消方法之后的唯一途径?

So currently there's no reference kept to the PendingIntent returned by the getBroadcast method. In a specific situation I now want to cancel the PendingIntent. Is there any way of getting the PendingIntent back from the View? Or is the only way to call the cancel method of the PendingIntent afterwards by keeping a reference to it?

推荐答案

如果你想取消的话,你会做以下(否则在code碱基的地方):

Where you want to cancel it, you would do the following (somewhere else in your code base):

PendingIntent.getBroadcast(context, 0, intent, 
                           PendingIntent.FLAG_UPDATE_CURRENT).cancel();

其中,意图是同一个作为参考在code以上。 PendingIntent.getBroadcast(...)使用 PendingIntent.FLAG_UPDATE_CURRENT 会返回一个引用现有的已创建的,或创建一个,如果它当前不存在

where intent is the same one as referenced in your code above. PendingIntent.getBroadcast(...) using the PendingIntent.FLAG_UPDATE_CURRENT will return a reference to the existing one already created, or create one if it doesn't currently exist.

这篇关于取消一个PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆