Build 1.0_r1(from source)

android.app
Class PendingIntent

java.lang.Object
  extended by android.app.PendingIntent
All Implemented Interfaces:
Parcelable

public final class PendingIntent
extends Object
implements Parcelable

A description of an Intent and target action to perform with it. Instances of this class are created with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), getService(android.content.Context, int, android.content.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: often, for example, the base Intent you supply will 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.


Nested Class Summary
static class 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.
static interface PendingIntent.OnFinished
          Callback interface for discovering when a send operation has completed.
 
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.Creator<T>
 
Field Summary
static Parcelable.Creator<PendingIntent> CREATOR
           
static int FLAG_CANCEL_CURRENT
          Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): if the described PendingIntent already exists, the current one is canceled before generating a new one.
static int FLAG_NO_CREATE
          Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): if the described PendingIntent does not already exist, then simply return null instead of creating it.
static int FLAG_ONE_SHOT
          Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): this PendingIntent can only be used once.
 
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
 
Constructor Summary
PendingIntent(IBinder target)
           
PendingIntent(IIntentSender target)
           
 
Method Summary
 void cancel()
          Cancel a currently active PendingIntent.
 int describeContents()
          Describe the kinds of special objects contained in this Parcelable's marshalled representation.
 boolean equals(Object otherObj)
          Comparison operator on two PendingIntent objects, such that true is returned then they both represent the same operation from the same package.
static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags)
          Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent).
static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags)
          Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().
static PendingIntent getService(Context context, int requestCode, Intent intent, int flags)
          Retrieve a PendingIntent that will start a service, like calling Context.startService().
(package private)  IIntentSender getTarget()
           
 String getTargetPackage()
          Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent.
 int hashCode()
          Returns an integer hash code for the receiver.
static PendingIntent readPendingIntentOrNullFromParcel(Parcel in)
          Convenience function for reading either a Messenger or null pointer from a Parcel.
 void send()
          Perform the operation associated with this PendingIntent.
 void send(Context context, int code, Intent intent)
          Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.
 void send(Context context, int code, Intent intent, PendingIntent.OnFinished onFinished, Handler 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.
 void send(int code)
          Perform the operation associated with this PendingIntent.
 void send(int code, PendingIntent.OnFinished onFinished, Handler handler)
          Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.
static void writePendingIntentOrNullToParcel(PendingIntent sender, Parcel out)
          Convenience function for writing either a PendingIntent or null pointer to a Parcel.
 void writeToParcel(Parcel out, int flags)
          Flatten this object in to a Parcel.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_ONE_SHOT

public static final int FLAG_ONE_SHOT
Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): this PendingIntent can only be used once. 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.

See Also:
Constant Field Values

FLAG_NO_CREATE

public static final int FLAG_NO_CREATE
Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): if the described PendingIntent does not already exist, then simply return null instead of creating it.

See Also:
Constant Field Values

FLAG_CANCEL_CURRENT

public static final int FLAG_CANCEL_CURRENT
Flag for use with getActivity(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), and getService(android.content.Context, int, android.content.Intent, int): if the described PendingIntent already exists, the current one is canceled before generating a new one. You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent.

See Also:
Constant Field Values

CREATOR

public static final Parcelable.Creator<PendingIntent> CREATOR
Constructor Detail

PendingIntent

PendingIntent(IIntentSender target)

PendingIntent

PendingIntent(IBinder target)
Method Detail

getActivity

public static PendingIntent getActivity(Context context,
                                        int requestCode,
                                        Intent intent,
                                        int flags)
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.

Parameters:
context - The Context in which this PendingIntent should start the activity.
requestCode - Private request code for the sender (currently not used).
intent - Intent of the activity to be launched.
flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_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.
Returns:
Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getBroadcast

public static PendingIntent getBroadcast(Context context,
                                         int requestCode,
                                         Intent intent,
                                         int flags)
Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

Parameters:
context - The Context in which this PendingIntent should perform the broadcast.
requestCode - Private request code for the sender (currently not used).
intent - The Intent to be broadcast.
flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_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.
Returns:
Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getService

public static PendingIntent getService(Context context,
                                       int requestCode,
                                       Intent intent,
                                       int flags)
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.

Parameters:
context - The Context in which this PendingIntent should start the service.
requestCode - Private request code for the sender (currently not used).
intent - An Intent describing the service to be started.
flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_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.
Returns:
Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

cancel

public void cancel()
Cancel a currently active PendingIntent. Only the original application owning an PendingIntent can cancel it.


send

public void send()
          throws PendingIntent.CanceledException
Perform the operation associated with this PendingIntent.

Throws:
PendingIntent.CanceledException - Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
See Also:
send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)

send

public void send(int code)
          throws PendingIntent.CanceledException
Perform the operation associated with this PendingIntent.

Parameters:
code - Result code to supply back to the PendingIntent's target.
Throws:
PendingIntent.CanceledException - Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
See Also:
send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)

send

public void send(Context context,
                 int code,
                 Intent intent)
          throws PendingIntent.CanceledException
Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.

Parameters:
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.
Throws:
PendingIntent.CanceledException - Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
See Also:
send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)

send

public void send(int code,
                 PendingIntent.OnFinished onFinished,
                 Handler handler)
          throws PendingIntent.CanceledException
Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.

Parameters:
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.
Throws:
PendingIntent.CanceledException - Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
See Also:
send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)

send

public void send(Context context,
                 int code,
                 Intent intent,
                 PendingIntent.OnFinished onFinished,
                 Handler handler)
          throws PendingIntent.CanceledException
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(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), or getService(android.content.Context, int, android.content.Intent, int).

Parameters:
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.
Throws:
PendingIntent.CanceledException - Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
See Also:
send(), send(int), send(Context, int, Intent), send(int, android.app.PendingIntent.OnFinished, Handler)

getTargetPackage

public String getTargetPackage()
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.

Returns:
The package name of the PendingIntent, or null if there is none associated with it.

equals

public boolean equals(Object otherObj)
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(android.content.Context, int, android.content.Intent, int), getBroadcast(android.content.Context, int, android.content.Intent, int), or getService(android.content.Context, int, android.content.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.

Overrides:
equals in class Object
Parameters:
otherObj - Object the object to compare with this object.
Returns:
boolean true if the object is the same as this object false if it is different from this object.
See Also:
Object.hashCode()

hashCode

public int hashCode()
Description copied from class: Object
Returns an integer hash code for the receiver. Any two objects which answer true when passed to .equals must answer the same value for this method.

Overrides:
hashCode in class Object
Returns:
int the receiver's hash.
See Also:
Object.equals(java.lang.Object)

describeContents

public int describeContents()
Description copied from interface: Parcelable
Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Specified by:
describeContents in interface Parcelable
Returns:
a bitmask indicating the set of special object types marshalled by the Parcelable.

writeToParcel

public void writeToParcel(Parcel out,
                          int flags)
Description copied from interface: Parcelable
Flatten this object in to a Parcel.

Specified by:
writeToParcel in interface Parcelable
Parameters:
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.PARCELABLE_WRITE_RETURN_VALUE.

writePendingIntentOrNullToParcel

public static void writePendingIntentOrNullToParcel(PendingIntent sender,
                                                    Parcel out)
Convenience function for writing either a PendingIntent or null pointer to a Parcel. You must use this with readPendingIntentOrNullFromParcel(android.os.Parcel) for later reading it.

Parameters:
sender - The PendingIntent to write, or null.
out - Where to write the PendingIntent.

readPendingIntentOrNullFromParcel

public static PendingIntent readPendingIntentOrNullFromParcel(Parcel in)
Convenience function for reading either a Messenger or null pointer from a Parcel. You must have previously written the Messenger with writePendingIntentOrNullToParcel(android.app.PendingIntent, android.os.Parcel).

Parameters:
in - The Parcel containing the written Messenger.
Returns:
Returns the Messenger read from the Parcel, or null if null had been written.

getTarget

IIntentSender getTarget()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature