Android Guides | Samples

Android.App.PendingIntent Class

A description of an Intent and target action to perform with it.

See Also: PendingIntent

Syntax

[Android.Runtime.Register("android/app/PendingIntent", DoNotGenerateAcw=true)]
public sealed class PendingIntent : Object, IParcelable, IDisposable

Remarks

A description of an Intent and target action to perform with it. Instances of this class are created with PendingIntent.GetActivity(Context,Int32,Int32,Int32), PendingIntent.GetActivities(Context,Int32,Int32,Int32), PendingIntent.GetBroadcast(Context,Int32,Int32,Int32), and PendingIntent.GetService(Context,Int32,Int32,Int32); the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.

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 PendingIntent.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(Intent). If you use two Intent objects that are equivalent as per Intent.FilterEquals(Intent), 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(Intent), or different request code integers supplied to PendingIntent.GetActivity(Context,Int32,Int32,Int32), PendingIntent.GetActivities(Context,Int32,Int32,Int32), PendingIntent.GetBroadcast(Context,Int32,Int32,Int32), or PendingIntent.GetService(Context,Int32,Int32,Int32).

If you only need one PendingIntent active at a time for any of the Intents you will use, then you can alternatively use the flags PendingIntentFlags.CancelCurrent or PendingIntentFlags.UpdateCurrent to either cancel or modify whatever current PendingIntent is associated with the Intent you are supplying.

[Android Documentation]

Requirements

Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.App.PendingIntent are listed below.

See Also: Object

Public Properties

[read-only]
static
CreatorIParcelableCreator.
[read-only]
CreatorPackageString. Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent.
[read-only]
CreatorUidInt32. Return the uid of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent.
[read-only]
CreatorUserHandleUserHandle. Return the user handle of the application that created this PendingIntent, that is the user under which you will actually be sending the Intent.
[read-only]
IntentSenderIntentSender. Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
[read-only]
TargetPackageString.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Cancel()
Cancel a currently active PendingIntent.
DescribeContents() : Int32
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
static
GetActivities(Context, Int32, Intent[], PendingIntentFlags) : PendingIntent
Like PendingIntent.GetActivity(Context,Int32,Int32,Int32), but allows an array of Intents to be supplied.
static
GetActivities(Context, Int32, Intent[], PendingIntentFlags, Bundle) : PendingIntent
Like PendingIntent.GetActivity(Context,Int32,Int32,Int32), but allows an array of Intents to be supplied.
static
GetActivity(Context, Int32, Intent, PendingIntentFlags) : PendingIntent
Retrieve a PendingIntent that will start a new activity, like calling Context.StartActivity(Intent).
static
GetActivity(Context, Int32, Intent, PendingIntentFlags, Bundle) : PendingIntent
Retrieve a PendingIntent that will start a new activity, like calling Context.StartActivity(Intent).
static
GetBroadcast(Context, Int32, Intent, PendingIntentFlags) : PendingIntent
Retrieve a PendingIntent that will perform a broadcast, like calling Context.SendBroadcast(Intent).
static
GetService(Context, Int32, Intent, PendingIntentFlags) : PendingIntent
Retrieve a PendingIntent that will start a service, like calling Context.StartService(Intent).
static
ReadPendingIntentOrNullFromParcel(Parcel) : PendingIntent
Convenience function for reading either a Messenger or null pointer from a Parcel.
Send()
Perform the operation associated with this PendingIntent.
Send(Result)
Perform the operation associated with this PendingIntent.
Send(Result, PendingIntent+IOnFinished, Handler)
Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.
Send(Context, Result, Intent)
Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.
Send(Context, Result, Intent, PendingIntent+IOnFinished, Handler)
Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.
Send(Context, Result, Intent, PendingIntent+IOnFinished, Handler, String)
Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.
static
WritePendingIntentOrNullToParcel(PendingIntent, Parcel)
Convenience function for writing either a PendingIntent or null pointer to a Parcel.
WriteToParcel(Parcel, ParcelableWriteFlags)
Flatten this object in to a Parcel.