ResultReceiverpublic class ResultReceiver extends Object implements ParcelableGeneric 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}.
Note: the implementation underneath is just a simple wrapper around
a {@link Binder} that is used to perform the communication. This means
semantically you should treat it as such: this class does not impact process
lifecycle management (you must be using some higher-level component to tell
the system that your process needs to continue running), the connection will
break if your process goes away for any reason, etc. |
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 int | describeContents()
return 0;
| protected void | onReceiveResult(int resultCode, Bundle resultData)Override to receive results delivered to this object.
| public void | send(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.
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 void | writeToParcel(Parcel out, int flags)
synchronized (this) {
if (mReceiver == null) {
mReceiver = new MyResultReceiver();
}
out.writeStrongBinder(mReceiver.asBinder());
}
|
|