public class ResultReceiver
extends Object implements Parcelable
| java.lang.Object | |
| android.os.ResultReceiver | |
用于接收某人的回调结果的通用接口。 通过创建一个子类并实现onReceiveResult(int, Bundle)它,然后您可以将其传递给其他人并通过IPC发送,并通过send(int, Bundle)接收他们提供的结果。
注意:下面的实现只是用于执行通信的简单包装Binder 。 这意味着你应该像这样对待它:这个类不影响流程生命周期管理(你必须使用一些更高级别的组件来告诉系统你的流程需要继续运行),如果你的流程消失,连接将会中断出于任何原因等等
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<ResultReceiver> |
CREATOR |
Public constructors |
|
|---|---|
ResultReceiver(Handler handler) 创建一个新的ResultReceive以接收结果。 |
|
公共方法(Public methods) |
|
|---|---|
int |
describeContents() 描述此Parcelable实例的封送表示中包含的特殊对象的种类。 |
void |
send(int resultCode, Bundle resultData) 将结果发送给此接收器。 |
void |
writeToParcel(Parcel out, int flags) 将此对象平铺到一个包裹中。 |
Protected methods |
|
|---|---|
void |
onReceiveResult(int resultCode, Bundle resultData) 重写以接收传递给此对象的结果。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.os.Parcelable
|
|
ResultReceiver (Handler handler)
创建一个新的ResultReceive以接收结果。 您的onReceiveResult(int, Bundle)方法将从线程运行处理程序(如果已提供)调用,或者从任意线程调用(如果为null)。
| 参数(Parameters) | |
|---|---|
handler |
Handler
|
int describeContents ()
描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。
| 返回(Returns) | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
void send (int resultCode,
Bundle resultData)
将结果发送给此接收器。 如果接收者提供了一个处理程序来调度结果,将总是异步调用onReceiveResult(int, Bundle) 。
| 参数(Parameters) | |
|---|---|
resultCode |
int: Arbitrary result code to deliver, as defined by you. |
resultData |
Bundle: Any additional data provided by you. |
void writeToParcel (Parcel out, int flags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
out |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |
void onReceiveResult (int resultCode,
Bundle resultData)
重写以接收传递给此对象的结果。
| 参数(Parameters) | |
|---|---|
resultCode |
int: Arbitrary result code delivered by the sender, as defined by the sender. |
resultData |
Bundle: Any additional data provided by the sender. |