如何创建不同的pendingintent所以filterEquals()返回false? [英] How to create different pendingintent so filterEquals() return false?

查看:245
本文介绍了如何创建不同的pendingintent所以filterEquals()返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用AlarmManager设置重复的意图,但它已经引起了一些小麻烦所以希望有人可以帮助。

I'm using AlarmManager to set up repeating intents but it has caused some little troubles so hope anyone could help.

摘要

有2个挂起的意图。一个运行在1000和其他运行在2000的每一天。每个包含一个行ID从数据库中进行识别。在code看起来是这样的:

There are 2 pending intents. One runs at 1000 and another runs at 2000 every day. Each contains a row id from the database for identification purpose. The code looks something like this:

Intent i = new Intent(mContext, ScheduleReceiver.class);
i.putExtra(RuleDBAdapter.KEY_ROWID, (int)taskId);
PendingIntent pi =PendingIntent.getBroadcast(...);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi); 

删除

的问题是,当我们需要删除其中之一。正确的方法来删除挂起的意图是建立一个相同的一个,然后调用从AlarmManager取消。

The problem is when we need to delete one of them. The proper way to delete a pending intent is to set up an identical one and then call cancel from AlarmManager.

Android的文档:

Android Documentation:

<一个href="http://developer.android.com/reference/android/app/AlarmManager.html#cancel%28android.app.PendingIntent%29">public无效取消(PendingIntent操作)
  与匹配的意图删除任何警报。任何报警,任何类型的,其意图匹配这一项,将被取消。

public void cancel (PendingIntent operation)
Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.

<一个href="http://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29">public布尔filterEquals(意向等)
  如果确定两个目的都是相同的意图分辨率(滤波)的目的。也就是说,如果它们的作用,数据,类型,类别和类别是相同的。这并不比任何额外的数据列入意图。

public boolean filterEquals (Intent other)
Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.

因此​​,在上面的例子,如果我做一个相同的目的,然后取消,上述两种意图的将被取消,因为他们是来自同一个类/同样的动作等(除了额外数据是ROWID,但 filterEquals 不关心额外的数据)。

So in the above example, if I make an identical intent then cancel, both of the above intents will get canceled, because they are from the same class/same action etc (except the "extra" data is rowId but filterEquals doesn't care about extra data).

有什么解决方法吗?

推荐答案

您可以创建挂起的意图,当尝试使用请求code参数:

You could try using the requestCode parameter when creating your pending intent:

PendingIntent pi =PendingIntent.getBroadcast(mContext, yourUniqueDatabaseId,i,PendingIntent.FLAG_ONE_SHOT);

这应该创建一个Intent是唯一匹配的目的。

This should create an Intent that is unique for matching purposes..

这篇关于如何创建不同的pendingintent所以filterEquals()返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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