FileDocCategorySizeDatePackage
Messenger.javaAPI DocAndroid 1.5 API4669Wed May 06 22:41:56 BST 2009android.os

Messenger

public final class Messenger extends Object implements Parcelable
Reference to a Handler, which others can use to send messages to it. This allows for the implementation of message-based communication across processes, by creating a Messenger pointing to a Handler in one process, and handing that Messenger to another process.

Fields Summary
private final IMessenger
mTarget
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Messenger(Handler target)
Create a new Messenger pointing to the given Handler. Any Message objects sent through this Messenger will appear in the Handler as if {@link Handler#sendMessage(Message) Handler.sendMessage(Message)} had be called directly.

param
target The Handler that will receive sent messages.

        mTarget = target.getIMessenger();
    
public Messenger(IBinder target)
Create a Messenger from a raw IBinder, which had previously been retrieved with {@link #getBinder}.

param
target The IBinder this Messenger should communicate with.

        mTarget = IMessenger.Stub.asInterface(target);
    
Methods Summary
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object otherObj)
Comparison operator on two Messenger objects, such that true is returned then they both point to the same Handler.

        if (otherObj == null) {
            return false;
        }
        try {
            return mTarget.asBinder().equals(((Messenger)otherObj)
                    .mTarget.asBinder());
        } catch (ClassCastException e) {
        }
        return false;
    
public IBindergetBinder()
Retrieve the IBinder that this Messenger is using to communicate with its associated Handler.

return
Returns the IBinder backing this Messenger.

        return mTarget.asBinder();
    
public inthashCode()

        return mTarget.asBinder().hashCode();
    
public static android.os.MessengerreadMessengerOrNullFromParcel(Parcel in)
Convenience function for reading either a Messenger or null pointer from a Parcel. You must have previously written the Messenger with {@link #writeMessengerOrNullToParcel}.

param
in The Parcel containing the written Messenger.
return
Returns the Messenger read from the Parcel, or null if null had been written.

        IBinder b = in.readStrongBinder();
        return b != null ? new Messenger(b) : null;
    
public voidsend(Message message)
Send a Message to this Messenger's Handler.

param
message The Message to send. Usually retrieved through {@link Message#obtain() Message.obtain()}.
throws
RemoteException Throws DeadObjectException if the target Handler no longer exists.

        mTarget.send(message);
    
public static voidwriteMessengerOrNullToParcel(android.os.Messenger messenger, Parcel out)
Convenience function for writing either a Messenger or null pointer to a Parcel. You must use this with {@link #readMessengerOrNullFromParcel} for later reading it.

param
messenger The Messenger to write, or null.
param
out Where to write the Messenger.


                                                  
        
              
        out.writeStrongBinder(messenger != null ? messenger.mTarget.asBinder()
                : null);
    
public voidwriteToParcel(Parcel out, int flags)

        out.writeStrongBinder(mTarget.asBinder());