如何获得并取消PendingIntent? [英] How to get and cancel a PendingIntent?

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

问题描述

我有一个 alarmManager 里面我是用将通知发送给在特定时间的用户。由于有多个报警,我有我创建,并给予一个唯一的ID多个挂起的意图,但也有一定的情况下,我需要得到所有悬而未决的意图,然后将其取消,这样我就可以重新设置报警。我试图做他的,我仍然不能似乎得到它的权利,所以我有几个问题:

I have an alarmManager which I am using to send notifications to the user at specific times. Since there are multiple alarms, I have multiple pending intents that I am creating and giving a unique ID, However there are certain situations in which I will need to get all the pending intents and then cancel them, so I can reset the alarms. I have tried doing his and I still cant seem to get it right so I have a couple questions:

这是你将如何正确地获取并取消 PendingIntent

Is this how you would correctly get and cancel a PendingIntent?

Intent intent = new Intent(con, AppointmentNotificationReciever.class);
PendingIntent sender = PendingIntent.getBroadcast(con, id, intent,
        PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
am.cancel(sender);

是否意图需要精确地匹配原始挂起的意图(临时演员及所有)的?

Does the intent need to exactly match that of the original pending intent(extras and all)?

请问 PendingIntent 标记需要匹配原始挂起的意图?

Does the PendingIntent flag need to match that of the original pending intent?

推荐答案

我发现,你实际上并没有得到待处理的意图......你必须完全重新创建它,因为它,当你第一次创建它(意向为好),然后将它传递给AlarmManager的取消功能。所以上面的code我贴真的不是不正确,只要那是我第一次创造了它。希望有人会发现这是很有帮助的。

I found out that you do not actually "get" the pending intent...you have to recreate it exactly as it was when you first created it(Intent as well) and then pass it to the AlarmManager's cancel function. So the above code I posted really is not incorrect as long as thats how I first created it. Hopefully someone will find this helpful.

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

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