java.lang.Object | |
↳ | android.app.PendingIntent |
A description of an Intent and target action to perform with it. Instances
of this class are created with getActivity(Context, int, Intent, int)
, getActivities(Context, int, Intent[], int)
,
getBroadcast(Context, int, Intent, int)
, and getService(Context, int, Intent, int)
; 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
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 per
Intent.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 flags
FLAG_CANCEL_CURRENT
or FLAG_UPDATE_CURRENT
to either
cancel or modify whatever current PendingIntent is associated with the
Intent you are supplying.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PendingIntent.CanceledException | Exception thrown when trying to send through a PendingIntent that has been canceled or is otherwise no longer able to execute the request. | ||||||||||
PendingIntent.OnFinished | Callback interface for discovering when a send operation has completed. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | FLAG_CANCEL_CURRENT | Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one. | |||||||||
int | FLAG_NO_CREATE | Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it. | |||||||||
int | FLAG_ONE_SHOT | Flag indicating that this PendingIntent can be used only once. | |||||||||
int | FLAG_UPDATE_CURRENT | Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CREATOR |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Cancel a currently active PendingIntent.
| |||||||||||
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
| |||||||||||
Comparison operator on two PendingIntent objects, such that true
is returned then they both represent the same operation from the
same package.
| |||||||||||
Like
getActivity(Context, int, Intent, int) , but allows an
array of Intents to be supplied.
| |||||||||||
Like
getActivity(Context, int, Intent, int) , but allows an
array of Intents to be supplied.
| |||||||||||
Retrieve a PendingIntent that will start a new activity, like calling
Context.startActivity(Intent) .
| |||||||||||
Retrieve a PendingIntent that will start a new activity, like calling
Context.startActivity(Intent) .
| |||||||||||
Retrieve a PendingIntent that will perform a broadcast, like calling
Context.sendBroadcast() .
| |||||||||||
Return the package name of the application that created this
PendingIntent, that is the identity under which you will actually be
sending the Intent.
| |||||||||||
Return the uid of the application that created this
PendingIntent, that is the identity under which you will actually be
sending the Intent.
| |||||||||||
Return the user handle of the application that created this
PendingIntent, that is the user under which you will actually be
sending the Intent.
| |||||||||||
Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
| |||||||||||
Retrieve a PendingIntent that will start a service, like calling
Context.startService() .
| |||||||||||
This method was deprecated
in API level 17.
Renamed to
getCreatorPackage() .
| |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Convenience function for reading either a Messenger or null pointer from
a Parcel.
| |||||||||||
Perform the operation associated with this PendingIntent.
| |||||||||||
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.
| |||||||||||
Perform the operation associated with this PendingIntent.
| |||||||||||
Perform the operation associated with this PendingIntent, allowing the
caller to specify information about the Intent to use.
| |||||||||||
Perform the operation associated with this PendingIntent, allowing the
caller to be notified when the send has completed.
| |||||||||||
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.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Convenience function for writing either a PendingIntent or null pointer to
a Parcel.
| |||||||||||
Flatten this object in to a Parcel.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.os.Parcelable
|
Flag indicating that if the described PendingIntent already exists,
the current one should be canceled before generating a new one.
For use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
, and
getService(Context, int, Intent, int)
.
You can use
this to retrieve a new PendingIntent when you are only changing the
extra data in the Intent; by canceling the previous pending intent,
this ensures that only entities given the new data will be able to
launch it. If this assurance is not an issue, consider
FLAG_UPDATE_CURRENT
.
Flag indicating that if the described PendingIntent does not
already exist, then simply return null instead of creating it.
For use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
, and
getService(Context, int, Intent, int)
.
Flag indicating that this PendingIntent can be used only once.
For use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
, and
getService(Context, int, Intent, int)
.
If set, after
send()
is called on it, it will be automatically
canceled for you and any future attempt to send through it will fail.
Flag indicating that if the described PendingIntent already exists,
then keep it but replace its extra data with what is in this new
Intent. For use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
, and
getService(Context, int, Intent, int)
.
This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
Cancel a currently active PendingIntent. Only the original application owning a PendingIntent can cancel it.
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
Comparison operator on two PendingIntent objects, such that true
is returned then they both represent the same operation from the
same package. This allows you to use getActivity(Context, int, Intent, int)
,
getBroadcast(Context, int, Intent, int)
, or getService(Context, int, Intent, int)
multiple times (even
across a process being killed), resulting in different PendingIntent
objects but whose equals() method identifies them as being the same
operation.
otherObj | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Like getActivity(Context, int, Intent, int)
, but allows an
array of Intents to be supplied. The last Intent in the array is
taken as the primary key for the PendingIntent, like the single Intent
given to getActivity(Context, int, Intent, int)
. Upon sending
the resulting PendingIntent, all of the Intents are started in the same
way as they would be by passing them to startActivities(Intent[])
.
The first intent in the array will be started outside of the context of an
existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
launch flag in the Intent. (Activities after
the first in the array are started in the context of the previous activity
in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
The last intent in the array represents the key for the
PendingIntent. In other words, it is the significant element for matching
(as done with the single intent given to getActivity(Context, int, Intent, int)
,
its content will be the subject of replacement by
send(Context, int, Intent)
and FLAG_UPDATE_CURRENT
, etc.
This is because it is the most specific of the supplied intents, and the
UI the user actually sees when the intents are started.
For security reasons, the Intent
objects
you supply here should almost always be explicit intents,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should start the activity. |
---|---|
requestCode | Private request code for the sender |
intents | Array of Intents of the activities to be launched. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
FLAG_NO_CREATE
has been
supplied.
Like getActivity(Context, int, Intent, int)
, but allows an
array of Intents to be supplied. The last Intent in the array is
taken as the primary key for the PendingIntent, like the single Intent
given to getActivity(Context, int, Intent, int)
. Upon sending
the resulting PendingIntent, all of the Intents are started in the same
way as they would be by passing them to startActivities(Intent[])
.
The first intent in the array will be started outside of the context of an
existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
launch flag in the Intent. (Activities after
the first in the array are started in the context of the previous activity
in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
The last intent in the array represents the key for the
PendingIntent. In other words, it is the significant element for matching
(as done with the single intent given to getActivity(Context, int, Intent, int)
,
its content will be the subject of replacement by
send(Context, int, Intent)
and FLAG_UPDATE_CURRENT
, etc.
This is because it is the most specific of the supplied intents, and the
UI the user actually sees when the intents are started.
For security reasons, the Intent
objects
you supply here should almost always be explicit intents,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should start the activity. |
---|---|
requestCode | Private request code for the sender |
intents | Array of Intents of the activities to be launched. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
FLAG_NO_CREATE
has been
supplied.
Retrieve a PendingIntent that will start a new activity, like calling
Context.startActivity(Intent)
.
Note that the activity will be started outside of the context of an
existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
launch flag in the Intent.
For security reasons, the Intent
you supply here should almost always be an explicit intent,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should start the activity. |
---|---|
requestCode | Private request code for the sender |
intent | Intent of the activity to be launched. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
FLAG_NO_CREATE
has been
supplied.
Retrieve a PendingIntent that will start a new activity, like calling
Context.startActivity(Intent)
.
Note that the activity will be started outside of the context of an
existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK
launch flag in the Intent.
For security reasons, the Intent
you supply here should almost always be an explicit intent,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should start the activity. |
---|---|
requestCode | Private request code for the sender |
intent | Intent of the activity to be launched. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
options | Additional options for how the Activity should be started. May be null if there are no options. |
FLAG_NO_CREATE
has been
supplied.
Retrieve a PendingIntent that will perform a broadcast, like calling
Context.sendBroadcast()
.
For security reasons, the Intent
you supply here should almost always be an explicit intent,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should perform the broadcast. |
---|---|
requestCode | Private request code for the sender |
intent | The Intent to be broadcast. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
FLAG_NO_CREATE
has been
supplied.
Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent. The returned string is supplied by the system, so that an application can not spoof its package.
Be careful about how you use this. All this tells you is
who created the PendingIntent. It does not tell you who
handed the PendingIntent to you: that is, PendingIntent objects are intended to be
passed between applications, so the PendingIntent you receive from an application
could actually be one it received from another application, meaning the result
you get here will identify the original application. Because of this, you should
only use this information to identify who you expect to be interacting with
through a send()
call, not who gave you the PendingIntent.
Return the uid of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent. The returned integer is supplied by the system, so that an application can not spoof its uid.
Be careful about how you use this. All this tells you is
who created the PendingIntent. It does not tell you who
handed the PendingIntent to you: that is, PendingIntent objects are intended to be
passed between applications, so the PendingIntent you receive from an application
could actually be one it received from another application, meaning the result
you get here will identify the original application. Because of this, you should
only use this information to identify who you expect to be interacting with
through a send()
call, not who gave you the PendingIntent.
Return the user handle of the application that created this
PendingIntent, that is the user under which you will actually be
sending the Intent. The returned UserHandle is supplied by the system, so
that an application can not spoof its user. See
Process.myUserHandle()
for
more explanation of user handles.
Be careful about how you use this. All this tells you is
who created the PendingIntent. It does not tell you who
handed the PendingIntent to you: that is, PendingIntent objects are intended to be
passed between applications, so the PendingIntent you receive from an application
could actually be one it received from another application, meaning the result
you get here will identify the original application. Because of this, you should
only use this information to identify who you expect to be interacting with
through a send()
call, not who gave you the PendingIntent.
Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
Retrieve a PendingIntent that will start a service, like calling
Context.startService()
. The start
arguments given to the service will come from the extras of the Intent.
For security reasons, the Intent
you supply here should almost always be an explicit intent,
that is specify an explicit component to be delivered to through
Intent.setClass
context | The Context in which this PendingIntent should start the service. |
---|---|
requestCode | Private request code for the sender |
intent | An Intent describing the service to be started. |
flags | May be FLAG_ONE_SHOT , FLAG_NO_CREATE ,
FLAG_CANCEL_CURRENT , FLAG_UPDATE_CURRENT ,
or any of the flags as supported by
Intent.fillIn() to control which unspecified parts
of the intent that can be supplied when the actual send happens. |
FLAG_NO_CREATE
has been
supplied.
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
Convenience function for reading either a Messenger or null pointer from
a Parcel. You must have previously written the Messenger with
writePendingIntentOrNullToParcel(PendingIntent, Parcel)
.
in | The Parcel containing the written Messenger. |
---|
Perform the operation associated with this PendingIntent.
code | Result code to supply back to the PendingIntent's target. |
---|
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
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.
For the intent parameter, a PendingIntent
often has restrictions on which fields can be supplied here, based on
how the PendingIntent was retrieved in getActivity(Context, int, Intent, int)
,
getBroadcast(Context, int, Intent, int)
, or getService(Context, int, Intent, int)
.
context | The Context of the caller. This may be null if intent is also null. |
---|---|
code | Result code to supply back to the PendingIntent's target. |
intent | Additional Intent data. See Intent.fillIn() for information on how this is applied to the
original Intent. Use null to not modify the original Intent. |
onFinished | The object to call back on when the send has completed, or null for no callback. |
handler | Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process. |
requiredPermission | Name of permission that a recipient of the PendingIntent
is required to hold. This is only valid for broadcast intents, and
corresponds to the permission argument in
Context.sendOrderedBroadcast(Intent, String) .
If null, no permission is required. |
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
Perform the operation associated with this PendingIntent.
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.
context | The Context of the caller. |
---|---|
code | Result code to supply back to the PendingIntent's target. |
intent | Additional Intent data. See Intent.fillIn() for information on how this is applied to the
original Intent. |
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.
code | Result code to supply back to the PendingIntent's target. |
---|---|
onFinished | The object to call back on when the send has completed, or null for no callback. |
handler | Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process. |
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
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.
For the intent parameter, a PendingIntent
often has restrictions on which fields can be supplied here, based on
how the PendingIntent was retrieved in getActivity(Context, int, Intent, int)
,
getBroadcast(Context, int, Intent, int)
, or getService(Context, int, Intent, int)
.
context | The Context of the caller. This may be null if intent is also null. |
---|---|
code | Result code to supply back to the PendingIntent's target. |
intent | Additional Intent data. See Intent.fillIn() for information on how this is applied to the
original Intent. Use null to not modify the original Intent. |
onFinished | The object to call back on when the send has completed, or null for no callback. |
handler | Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process. |
PendingIntent.CanceledException | Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it. |
---|
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
Convenience function for writing either a PendingIntent or null pointer to
a Parcel. You must use this with readPendingIntentOrNullFromParcel(Parcel)
for later reading it.
sender | The PendingIntent to write, or null. |
---|---|
out | Where to write the PendingIntent. |
Flatten this object in to a Parcel.
out | The Parcel in which the object should be written. |
---|---|
flags | Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE .
|