用来描述Intent和要执行的动作。
实例化要通过PendingIntent.getBroadcast (),
getActivity(Context, int, Intent, int), getActivities(Context, int, Intent[], int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int);
By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: almost always, for example, the base Intent you supply should have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.
A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it.
Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent.filterEquals. If you use two Intent objects that are equivalent as perIntent.filterEquals, then you will get the same PendingIntent for both of them.
There are two typical ways to deal with this.
If you truly need multiple distinct PendingIntent objects active at the same time (such as to use as two notifications that are both shown at the same time), then you will need to ensure there is something that is different about them to associate them with different PendingIntents. This may be any of the Intent attributes considered by Intent.filterEquals, or different request code integers supplied to getActivity(Context, int, Intent, int), getActivities(Context, int, Intent[], int),getBroadcast(Context, int, Intent, int), or getService(Context, int, Intent, int).
If you only need one PendingIntent active at a time for any of the Intents you will use, then you can alternatively use the flagsFLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT to either cancel or modify whatever current PendingIntent is associated with the Intent you are supplying.
区分2个PendingIntent是否相同的因素:1,Intent的属性,defined by Intent.filterEquals 2,requestCode。
当PendingIntent是同一个时,处理这种情况用Flag。
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.Returns true if action, data, type, class, and categories are the same.
public boolean filterEquals(Intent other) { if (other == null) { return false; } if (mAction != other.mAction) { if (mAction != null) { if (!mAction.equals(other.mAction)) { return false; } } else { if (!other.mAction.equals(mAction)) { return false; } } } if (mData != other.mData) { if (mData != null) { if (!mData.equals(other.mData)) { return false; } } else { if (!other.mData.equals(mData)) { return false; } } } if (mType != other.mType) { if (mType != null) { if (!mType.equals(other.mType)) { return false; } } else { if (!other.mType.equals(mType)) { return false; } } } if (mPackage != other.mPackage) { if (mPackage != null) { if (!mPackage.equals(other.mPackage)) { return false; } } else { if (!other.mPackage.equals(mPackage)) { return false; } } } if (mComponent != other.mComponent) { if (mComponent != null) { if (!mComponent.equals(other.mComponent)) { return false; } } else { if (!other.mComponent.equals(mComponent)) { return false; } } } if (mCategories != other.mCategories) { if (mCategories != null) { if (!mCategories.equals(other.mCategories)) { return false; } } else { if (!other.mCategories.equals(mCategories)) { return false; } } } return true; }