FileDocCategorySizeDatePackage
ResultReceiver.javaAPI DocAndroid 1.5 API4182Wed May 06 22:41:56 BST 2009android.os

ResultReceiver

public class ResultReceiver extends Object implements Parcelable
Generic interface for receiving a callback result from someone. Use this by creating a subclass and implement {@link #onReceiveResult}, which you can then pass to others and send through IPC, and receive results they supply with {@link #send}.

Fields Summary
final boolean
mLocal
final Handler
mHandler
com.android.internal.os.IResultReceiver
mReceiver
public static final Parcelable.Creator
CREATOR
Constructors Summary
public ResultReceiver(Handler handler)
Create a new ResultReceive to receive results. Your {@link #onReceiveResult} method will be called from the thread running handler if given, or from an arbitrary thread if null.

        mLocal = true;
        mHandler = handler;
    
ResultReceiver(Parcel in)

        mLocal = false;
        mHandler = null;
        mReceiver = IResultReceiver.Stub.asInterface(in.readStrongBinder());
    
Methods Summary
public intdescribeContents()

        return 0;
    
protected voidonReceiveResult(int resultCode, Bundle resultData)
Override to receive results delivered to this object.

param
resultCode Arbitrary result code delivered by the sender, as defined by the sender.
param
resultData Any additional data provided by the sender.

    
public voidsend(int resultCode, Bundle resultData)
Deliver a result to this receiver. Will call {@link #onReceiveResult}, always asynchronously if the receiver has supplied a Handler in which to dispatch the result.

param
resultCode Arbitrary result code to deliver, as defined by you.
param
resultData Any additional data provided by you.

        if (mLocal) {
            if (mHandler != null) {
                mHandler.post(new MyRunnable(resultCode, resultData));
            } else {
                onReceiveResult(resultCode, resultData);
            }
            return;
        }
        
        if (mReceiver != null) {
            try {
                mReceiver.send(resultCode, resultData);
            } catch (RemoteException e) {
            }
        }
    
public voidwriteToParcel(Parcel out, int flags)

        synchronized (this) {
            if (mReceiver == null) {
                mReceiver = new MyResultReceiver();
            }
            out.writeStrongBinder(mReceiver.asBinder());
        }