public
final
class
Messenger
extends Object
implements
Parcelable
java.lang.Object | |
↳ | 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 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.
Inherited constants |
---|
From
interface
android.os.Parcelable
|
Fields | |
---|---|
public
static
final
Creator<Messenger> |
CREATOR
|
Public constructors | |
---|---|
Messenger(Handler target)
Create a new Messenger pointing to the given Handler. |
|
Messenger(IBinder target)
Create a Messenger from a raw IBinder, which had previously been
retrieved with |
Public methods | |
---|---|
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
boolean
|
equals(Object otherObj)
Comparison operator on two Messenger objects, such that true is returned then they both point to the same Handler. |
IBinder
|
getBinder()
Retrieve the IBinder that this Messenger is using to communicate with its associated Handler. |
int
|
hashCode()
Returns a hash code value for the object. |
static
Messenger
|
readMessengerOrNullFromParcel(Parcel in)
Convenience function for reading either a Messenger or null pointer from a Parcel. |
void
|
send(Message message)
Send a Message to this Messenger's Handler. |
static
void
|
writeMessengerOrNullToParcel(Messenger messenger, Parcel out)
Convenience function for writing either a Messenger or null pointer to a Parcel. |
void
|
writeToParcel(Parcel out, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
---|---|
From
class
java.lang.Object
| |
From
interface
android.os.Parcelable
|
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
Handler.sendMessage(Message)
had
been called directly.
Parameters | |
---|---|
target |
Handler :
The Handler that will receive sent messages.
|
Messenger (IBinder target)
Create a Messenger from a raw IBinder, which had previously been
retrieved with getBinder()
.
Parameters | |
---|---|
target |
IBinder :
The IBinder this Messenger should communicate with.
|
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 writeToParcel(Parcel, int)
,
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR
bit.
Returns | |
---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
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 :
the reference object with which to compare. |
Returns | |
---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
IBinder getBinder ()
Retrieve the IBinder that this Messenger is using to communicate with its associated Handler.
Returns | |
---|---|
IBinder |
Returns the IBinder backing this Messenger. |
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
HashMap
.
The general contract of hashCode
is:
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.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
equals(java.lang.Object)
method, then calling 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
JavaTM programming language.)
Returns | |
---|---|
int |
a hash code value for this object. |
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
writeMessengerOrNullToParcel(Messenger, Parcel)
.
Parameters | |
---|---|
in |
Parcel :
The Parcel containing the written Messenger. |
Returns | |
---|---|
Messenger |
Returns the Messenger read from the Parcel, or null if null had been written. |
void send (Message message)
Send a Message to this Messenger's Handler.
Parameters | |
---|---|
message |
Message :
The Message to send. Usually retrieved through
Message.obtain() . |
Throws | |
---|---|
RemoteException |
Throws DeadObjectException if the target Handler no longer exists. |
void writeMessengerOrNullToParcel (Messenger messenger, Parcel out)
Convenience function for writing either a Messenger or null pointer to
a Parcel. You must use this with readMessengerOrNullFromParcel(Parcel)
for later reading it.
Parameters | |
---|---|
messenger |
Messenger :
The Messenger to write, or null. |
out |
Parcel :
Where to write the Messenger.
|
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 PARCELABLE_WRITE_RETURN_VALUE .
|