java.lang.Object | |
↳ | android.os.Message |
Defines a message containing a description and arbitrary data object that can be sent to a Handler. This object contains two extra int fields and an extra object field that allow you to not do allocations in many cases.
While the constructor of Message is public, the best way to get one of these is to call Message.obtain() or one of the Handler.obtainMessage() methods, which will pull them from a pool of recycled objects.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creator<Message> | CREATOR |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
arg1 | arg1 and arg2 are lower-cost alternatives to using setData() if you only need to store a few integer values. | ||||||||||
arg2 | arg1 and arg2 are lower-cost alternatives to using setData() if you only need to store a few integer values. | ||||||||||
obj | An arbitrary object to send to the recipient. | ||||||||||
replyTo | Optional Messenger where replies to this message can be sent. | ||||||||||
what | User-defined message code so that the recipient can identify what this message is about. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor (but the preferred way to get a Message is to call Message.obtain()).
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Make this message like o.
| |||||||||||
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
| |||||||||||
Retrieve callback object that will execute when this message is handled.
| |||||||||||
Obtains a Bundle of arbitrary data associated with this
event, lazily creating it if necessary.
| |||||||||||
Retrieve the a Handler implementation that
will receive this message.
| |||||||||||
Return the targeted delivery time of this message, in milliseconds.
| |||||||||||
Return a new Message instance from the global pool.
| |||||||||||
Same as obtain(), but copies the values of an existing
message (including its target) into the new one.
| |||||||||||
Same as obtain(), but sets the value for the target member on the Message returned.
| |||||||||||
Same as obtain(Handler), but assigns a callback Runnable on
the Message that is returned.
| |||||||||||
Same as obtain(), but sets the values of the target, what,
arg1, and arg2 members.
| |||||||||||
Same as obtain(), but sets the values for both target and
what members on the Message.
| |||||||||||
Same as obtain(), but sets the values of the target, what, and obj
members.
| |||||||||||
Same as obtain(), but sets the values of the target, what,
arg1, arg2, and obj members.
| |||||||||||
Like getData(), but does not lazily create the Bundle.
| |||||||||||
Return a Message instance to the global pool.
| |||||||||||
Sends this Message to the Handler specified by getTarget().
| |||||||||||
Sets a Bundle of arbitrary data values.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Flatten this object in to a Parcel.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface android.os.Parcelable
|
arg1 and arg2 are lower-cost alternatives to using setData() if you only need to store a few integer values.
arg1 and arg2 are lower-cost alternatives to using setData() if you only need to store a few integer values.
An arbitrary object to send to the recipient. This must be null when sending messages across processes.
Optional Messenger where replies to this message can be sent.
User-defined message code so that the recipient can identify what this message is about. Each Handler has its own name-space for message codes, so you do not need to worry about yours conflicting with other handlers.
Constructor (but the preferred way to get a Message is to call Message.obtain()).
Make this message like o. Performs a shallow copy of the data field. Does not copy the linked list fields, nor the timestamp or target/callback of the original message.
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
Retrieve callback object that will execute when this message is handled. This object must implement Runnable. This is called by the target Handler that is receiving this Message to dispatch it. If not set, the message will be dispatched to the receiving Handler's handleMessage(Message).
Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary. Set this value by calling setData(Bundle).
Retrieve the a Handler implementation that will receive this message. The object must implement Handler.handleMessage(). Each Handler has its own name-space for message codes, so you do not need to worry about yours conflicting with other handlers.
Return the targeted delivery time of this message, in milliseconds.
Return a new Message instance from the global pool. Allows us to avoid allocating new objects in many cases.
Same as obtain(), but copies the values of an existing message (including its target) into the new one.
orig | Original message to copy. |
---|
Same as obtain(), but sets the value for the target member on the Message returned.
h | Handler to assign to the returned Message object's target member. |
---|
Same as obtain(Handler), but assigns a callback Runnable on the Message that is returned.
h | Handler to assign to the returned Message object's target member. |
---|---|
callback | Runnable that will execute when the message is handled. |
Same as obtain(), but sets the values of the target, what, arg1, and arg2 members.
h | The target value to set. |
---|---|
what | The what value to set. |
arg1 | The arg1 value to set. |
arg2 | The arg2 value to set. |
Same as obtain(), but sets the values for both target and what members on the Message.
h | Value to assign to the target member. |
---|---|
what | Value to assign to the what member. |
Same as obtain(), but sets the values of the target, what, and obj members.
h | The target value to set. |
---|---|
what | The what value to set. |
obj | The object method to set. |
Same as obtain(), but sets the values of the target, what, arg1, arg2, and obj members.
h | The target value to set. |
---|---|
what | The what value to set. |
arg1 | The arg1 value to set. |
arg2 | The arg2 value to set. |
obj | The obj value to set. |
Like getData(), but does not lazily create the Bundle. A null is returned if the Bundle does not already exist.
Return a Message instance to the global pool. You MUST NOT touch the Message after calling this function -- it has effectively been freed.
Sends this Message to the Handler specified by getTarget(). Throws a null pointer exception if this field has not been set.
Sets a Bundle of arbitrary data values. Use arg1 and arg1 members as a lower cost way to send a few simple integer values, if you can.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Flatten this object in to a Parcel.
dest | The Parcel in which the object should be written. |
---|---|
flags | Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |