messenger android 4.,Messenger  |  Android 开发者  |  Android Developers

Messenger

public

final

class

Messenger

extends Object

implements

Parcelable↳

android.os.Messenger

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.

Note: the implementation underneath is just a simple wrapper around

a

Summary

Inherited constants

int

Descriptor bit used with

int

Flag for use with Parcelable someFunction()",

"void someFunction(out Parcelable)", or

"void someFunction(inout Parcelable)".

Fields

public

static

final

Creator

Public constructors

Create a new Messenger pointing to the given Handler.

Create a Messenger from a raw IBinder, which had previously been

retrieved with

Public methods

int

Describe the kinds of special objects contained in this Parcelable

instance's marshaled representation.

boolean

Comparison operator on two Messenger objects, such that true

is returned then they both point to the same Handler.

Retrieve the IBinder that this Messenger is using to communicate with

its associated Handler.

int

Returns a hash code value for the object.

Convenience function for reading either a Messenger or null pointer from

a Parcel.

void

Send a Message to this Messenger's Handler.

static

void

Convenience function for writing either a Messenger or null pointer to

a Parcel.

void

Flatten this object in to a Parcel.

Inherited methods

Creates and returns a copy of this object.

boolean

Indicates whether some other object is "equal to" this one.

void

Called by the garbage collector on an object when garbage collection

determines that there are no more references to the object.

final

Class>

Returns the runtime class of this Object.

int

Returns a hash code value for the object.

final

void

Wakes up a single thread that is waiting on this object's

monitor.

final

void

Wakes up all threads that are waiting on this object's monitor.

Returns a string representation of the object.

final

void

wait(long timeout, int nanos)

Causes the current thread to wait until another thread invokes the

final

void

wait(long timeout)

Causes the current thread to wait until either another thread invokes the

final

void

Causes the current thread to wait until another thread invokes the

abstract

int

Describe the kinds of special objects contained in this Parcelable

instance's marshaled representation.

abstract

void

Flatten this object in to a Parcel.

Fields

CREATOR

public static final Creator CREATOR

Public constructors

Messenger

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

Parameters

target

Handler: The Handler that will receive sent messages.

Messenger

public Messenger (IBinder target)

Create a Messenger from a raw IBinder, which had previously been

retrieved with

Parameters

target

IBinder: The IBinder this Messenger should communicate with.

Public methods

describeContents

public int describeContents ()

Describe the kinds of special objects contained in this Parcelable

instance's marshaled representation. For example, if the object will

include a file descriptor in the output of

Returns

int

a bitmask indicating the set of special object types marshaled

by this Parcelable object instance.

Value is either 0 or

equals

public boolean equals (Object otherObj)

Comparison operator on two Messenger objects, such that true

is returned then they both point to the same Handler.

Parameters

otherObj

Object: This value may be null.

Returns

boolean

true if this object is the same as the obj

argument; false otherwise.

getBinder

public IBinder getBinder ()

Retrieve the IBinder that this Messenger is using to communicate with

its associated Handler.

Returns

Returns the IBinder backing this Messenger.

hashCode

public int hashCode ()

Returns a hash code value for the object. This method is

supported for the benefit of hash tables such as those provided by

The general contract of hashCode is:Whenever it is invoked on the same object more than once during

an execution of a Java application, the hashCode method

must consistently return the same integer, provided no information

used in equals comparisons on the object is modified.

This integer need not remain consistent from one execution of an

application to another execution of the same application.

If two objects are equal according to the equals(Object)

method, then calling the hashCode method on each of

the two objects must produce the same integer result.

It is not required that if two objects are unequal

according to the hashCode method on each of the

two objects must produce distinct integer results. However, the

programmer should be aware that producing distinct integer results

for unequal objects may improve the performance of hash tables.

As much as is reasonably practical, the hashCode method defined by

class Object does return distinct integers for distinct

objects. (This is typically implemented by converting the internal

address of the object into an integer, but this implementation

technique is not required by the

Java™ programming language.)

Returns

int

a hash code value for this object.

readMessengerOrNullFromParcel

public static Messenger readMessengerOrNullFromParcel (Parcel in)

Convenience function for reading either a Messenger or null pointer from

a Parcel. You must have previously written the Messenger with

Parameters

in

Parcel: The Parcel containing the written Messenger.

Returns

Returns the Messenger read from the Parcel, or null if null had

been written.

send

public void send (Message message)

Send a Message to this Messenger's Handler.

Parameters

message

Message: The Message to send. Usually retrieved through

Throws

Throws DeadObjectException if the target

Handler no longer exists.

writeMessengerOrNullToParcel

public static void writeMessengerOrNullToParcel (Messenger messenger,

Parcel out)

Convenience function for writing either a Messenger or null pointer to

a Parcel. You must use this with

Parameters

messenger

Messenger: The Messenger to write, or null.

out

Parcel: Where to write the Messenger.

writeToParcel

public void writeToParcel (Parcel out,

int flags)

Flatten this object in to a Parcel.

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 0 or a combination of

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值