Most visited

Recently visited

Added in API level 3

ResultReceiver

public class ResultReceiver
extends Object implements Parcelable

java.lang.Object
   ↳ android.os.ResultReceiver


用于接收某人的回调结果的通用接口。 通过创建一个子类并实现onReceiveResult(int, Bundle)它,然后您可以将其传递给其他人并通过IPC发送,并通过send(int, Bundle)接收他们提供的结果。

注意:下面的实现只是用于执行通信的简单包装Binder 这意味着你应该像这样对待它:这个类不影响流程生命周期管理(你必须使用一些更高级别的组件来告诉系统你的流程需要继续运行),如果你的流程消失,连接将会中断出于任何原因等等

Summary

Inherited constants

From interface 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

From class java.lang.Object
From interface android.os.Parcelable

Fields

CREATOR

Added in API level 3
Creator<ResultReceiver> CREATOR

Public constructors

ResultReceiver

Added in API level 3
ResultReceiver (Handler handler)

创建一个新的ResultReceive以接收结果。 您的onReceiveResult(int, Bundle)方法将从线程运行处理程序(如果已提供)调用,或者从任意线程调用(如果为null)。

Parameters
handler Handler

Public methods

describeContents

Added in API level 3
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.

send

Added in API level 3
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.

writeToParcel

Added in API level 3
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.

Protected methods

onReceiveResult

Added in API level 3
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.

Hooray!