# Message

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Inherited Constants](https://developer.android.com/reference/android/os/Message#inhconstants)\|[Fields](https://developer.android.com/reference/android/os/Message#lfields)\|[Ctors](https://developer.android.com/reference/android/os/Message#pubctors)\|[Methods](https://developer.android.com/reference/android/os/Message#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/os/Message#inhmethods)  

# Message

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/os/Message "View this page in Kotlin")\|Java

`
public

final

class
Message
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Parcelable](https://developer.android.com/reference/android/os/Parcelable)`


`

|---|--------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.Message |

<br />

*** ** * ** ***

Defines a message containing a description and arbitrary data object that can be sent to a[Handler](https://developer.android.com/reference/android/os/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()](https://developer.android.com/reference/android/os/Message#obtain())or one of the[Handler.obtainMessage()](https://developer.android.com/reference/android/os/Handler#obtainMessage())methods, which will pull them from a pool of recycled objects.

<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ### Inherited constants                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From interface[android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable) |-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `int` | [CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR) Descriptor bit used with[describeContents()](https://developer.android.com/reference/android/os/Parcelable#describeContents()): indicates that the Parcelable object's flattened representation includes a file descriptor.                                                                                                                                            | | `int` | [PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE) Flag for use with[writeToParcel(Parcel, int)](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)): the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`". | |

|                                                                                                                                                                                                                           ### Fields                                                                                                                                                                                                                            ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static final `[Creator](https://developer.android.com/reference/android/os/Parcelable.Creator)`<`[Message](https://developer.android.com/reference/android/os/Message)`>` | [CREATOR](https://developer.android.com/reference/android/os/Message#CREATOR) <br />                                                                                                                                                                                        |
| ` public int`                                                                                                                                                                      | [arg1](https://developer.android.com/reference/android/os/Message#arg1) arg1 and arg2 are lower-cost alternatives to using[setData()](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))if you only need to store a few integer values. |
| ` public int`                                                                                                                                                                      | [arg2](https://developer.android.com/reference/android/os/Message#arg2) arg1 and arg2 are lower-cost alternatives to using[setData()](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))if you only need to store a few integer values. |
| ` public `[Object](https://developer.android.com/reference/java/lang/Object)                                                                                                       | [obj](https://developer.android.com/reference/android/os/Message#obj) An arbitrary object to send to the recipient.                                                                                                                                                         |
| ` public `[Messenger](https://developer.android.com/reference/android/os/Messenger)                                                                                                | [replyTo](https://developer.android.com/reference/android/os/Message#replyTo) Optional Messenger where replies to this message can be sent.                                                                                                                                 |
| ` public int`                                                                                                                                                                      | [sendingUid](https://developer.android.com/reference/android/os/Message#sendingUid) Optional field indicating the uid that sent the message.                                                                                                                                |
| ` public int`                                                                                                                                                                      | [what](https://developer.android.com/reference/android/os/Message#what) User-defined message code so that the recipient can identify what this message is about.                                                                                                            |

|                                                                                                              ### Public constructors                                                                                                               ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Message](https://developer.android.com/reference/android/os/Message#Message())`() ` Constructor (but the preferred way to get a Message is to call[Message.obtain()](https://developer.android.com/reference/android/os/Message#obtain())). |

|                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                    ||
|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                         | ` `[copyFrom](https://developer.android.com/reference/android/os/Message#copyFrom(android.os.Message))`(`[Message](https://developer.android.com/reference/android/os/Message)` o) ` Make this message like o.                                                                                                                                                                                                                                                                                          |
| ` int`                                                                          | ` `[describeContents](https://developer.android.com/reference/android/os/Message#describeContents())`() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.                                                                                                                                                                                                                                                                                       |
| ` `[Runnable](https://developer.android.com/reference/java/lang/Runnable)       | ` `[getCallback](https://developer.android.com/reference/android/os/Message#getCallback())`() ` Retrieve callback object that will execute when this message is handled.                                                                                                                                                                                                                                                                                                                                |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)          | ` `[getData](https://developer.android.com/reference/android/os/Message#getData())`() ` Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.                                                                                                                                                                                                                                                                                                                 |
| ` `[Handler](https://developer.android.com/reference/android/os/Handler)        | ` `[getTarget](https://developer.android.com/reference/android/os/Message#getTarget())`() ` Retrieve the[Handler](https://developer.android.com/reference/android/os/Handler)implementation that will receive this message.                                                                                                                                                                                                                                                                             |
| ` long`                                                                         | ` `[getWhen](https://developer.android.com/reference/android/os/Message#getWhen())`() ` Return the targeted delivery time of this message, in milliseconds.                                                                                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                      | ` `[isAsynchronous](https://developer.android.com/reference/android/os/Message#isAsynchronous())`() ` Returns true if the message is asynchronous, meaning that it is not subject to[Looper](https://developer.android.com/reference/android/os/Looper)synchronization barriers.                                                                                                                                                                                                                        |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the value for the*target*member on the Message returned.                                                                                                                                                              |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler,%20int))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h, int what) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values for both*target* and*what*members on the Message.                                                                                                                                         |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler,%20java.lang.Runnable))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h, `[Runnable](https://developer.android.com/reference/java/lang/Runnable)` callback) ` Same as[obtain(android.os.Handler)](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler)), but assigns a callback Runnable on the Message that is returned.                  |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Message))`(`[Message](https://developer.android.com/reference/android/os/Message)` orig) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but copies the values of an existing message (including its target) into the new one.                                                                                                                                       |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler,%20int,%20int,%20int,%20java.lang.Object))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h, int what, int arg1, int arg2, `[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* ,*arg1* ,*arg2* , and*obj*members. |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler,%20int,%20int,%20int))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h, int what, int arg1, int arg2) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* ,*arg1* , and*arg2*members.                                                                                                      |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler,%20int,%20java.lang.Object))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` h, int what, `[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* , and*obj*members.                                                   |
| ` static `[Message](https://developer.android.com/reference/android/os/Message) | ` `[obtain](https://developer.android.com/reference/android/os/Message#obtain())`() ` Return a new Message instance from the global pool.                                                                                                                                                                                                                                                                                                                                                               |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)          | ` `[peekData](https://developer.android.com/reference/android/os/Message#peekData())`() ` Like getData(), but does not lazily create the Bundle.                                                                                                                                                                                                                                                                                                                                                        |
| ` void`                                                                         | ` `[recycle](https://developer.android.com/reference/android/os/Message#recycle())`() ` Return a Message instance to the global pool.                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                         | ` `[sendToTarget](https://developer.android.com/reference/android/os/Message#sendToTarget())`() ` Sends this Message to the Handler specified by[getTarget()](https://developer.android.com/reference/android/os/Message#getTarget()).                                                                                                                                                                                                                                                                  |
| ` void`                                                                         | ` `[setAsynchronous](https://developer.android.com/reference/android/os/Message#setAsynchronous(boolean))`(boolean async) ` Sets whether the message is asynchronous, meaning that it is not subject to[Looper](https://developer.android.com/reference/android/os/Looper)synchronization barriers.                                                                                                                                                                                                     |
| ` void`                                                                         | ` `[setData](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` data) ` Sets a Bundle of arbitrary data values.                                                                                                                                                                                                                                                                              |
| ` void`                                                                         | ` `[setTarget](https://developer.android.com/reference/android/os/Message#setTarget(android.os.Handler))`(`[Handler](https://developer.android.com/reference/android/os/Handler)` target) `                                                                                                                                                                                                                                                                                                             |
| ` `[String](https://developer.android.com/reference/java/lang/String)           | ` `[toString](https://developer.android.com/reference/android/os/Message#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                         | ` `[writeToParcel](https://developer.android.com/reference/android/os/Message#writeToParcel(android.os.Parcel,%20int))`(`[Parcel](https://developer.android.com/reference/android/os/Parcel)` dest, int flags) ` Flatten this object in to a Parcel.                                                                                                                                                                                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable)` ` |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int`  | ` `[describeContents](https://developer.android.com/reference/android/os/Parcelable#describeContents())`() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.                                    | | ` abstract void` | ` `[writeToParcel](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int))`(`[Parcel](https://developer.android.com/reference/android/os/Parcel)` dest, int flags) ` Flatten this object in to a Parcel. | ||

## Fields

### CREATOR

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Creator<Message> CREATOR
```

<br />

<br />

### arg1

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int arg1
```

arg1 and arg2 are lower-cost alternatives to using[setData()](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))if you only need to store a few integer values.

<br />

### arg2

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int arg2
```

arg1 and arg2 are lower-cost alternatives to using[setData()](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))if you only need to store a few integer values.

<br />

### obj

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Object obj
```

An arbitrary object to send to the recipient. When using[Messenger](https://developer.android.com/reference/android/os/Messenger)to send the message across processes this can only be non-null if it contains a Parcelable of a framework class (not one implemented by the application). For other data transfer use[setData(Bundle)](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle)).

Note that Parcelable objects here are not supported prior to the[Build.VERSION_CODES.FROYO](https://developer.android.com/reference/android/os/Build.VERSION_CODES#FROYO)release.

<br />

### replyTo

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Messenger replyTo
```

Optional Messenger where replies to this message can be sent. The semantics of exactly how this is used are up to the sender and receiver.

<br />

### sendingUid

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int sendingUid
```

Optional field indicating the uid that sent the message. This is only valid for messages posted by a[Messenger](https://developer.android.com/reference/android/os/Messenger); otherwise, it will be -1.

<br />

### what

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int what
```

User-defined message code so that the recipient can identify what this message is about. Each[Handler](https://developer.android.com/reference/android/os/Handler)has its own name-space for message codes, so you do not need to worry about yours conflicting with other handlers. If not specified, this value is 0. Use values other than 0 to indicate custom message codes.

<br />

## Public constructors

### Message

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Message ()
```

Constructor (but the preferred way to get a Message is to call[Message.obtain()](https://developer.android.com/reference/android/os/Message#obtain())).

<br />

## Public methods

### copyFrom

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void copyFrom (Message o)
```

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.

<br />

|      Parameters       ||
|-----|------------------|
| `o` | `Message` <br /> |

### describeContents

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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[writeToParcel(android.os.Parcel, int)](https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)), the return value of this method must include the[CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR)bit.

<br />

|                                                                                                                         Returns                                                                                                                         ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either`0`or[CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR) <br /> |

### getCallback

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Runnable getCallback ()
```

Retrieve callback object that will execute when this message is handled. This object must implement Runnable. This is called by the*target* [Handler](https://developer.android.com/reference/android/os/Handler)that is receiving this Message to dispatch it. If not set, the message will be dispatched to the receiving Handler's[Handler.handleMessage(Message)](https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)).

<br />

|                                    Returns                                     ||
|------------------------------------------------------------------------|--------|
| [Runnable](https://developer.android.com/reference/java/lang/Runnable) | <br /> |

### getData

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Bundle getData ()
```

Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary. Set this value by calling[setData(android.os.Bundle)](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle)). Note that when transferring data across processes via[Messenger](https://developer.android.com/reference/android/os/Messenger), you will need to set your ClassLoader on the Bundle via[Bundle.setClassLoader()](https://developer.android.com/reference/android/os/Bundle#setClassLoader(java.lang.ClassLoader))so that it can instantiate your objects when you retrieve them.

<br />

|                                   Returns                                   ||
|---------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle) | <br /> |

**See also:**

- [peekData()](https://developer.android.com/reference/android/os/Message#peekData())
- [setData(Bundle)](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))  

### getTarget

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Handler getTarget ()
```

Retrieve the[Handler](https://developer.android.com/reference/android/os/Handler)implementation that will receive this message. The object must implement[Handler.handleMessage()](https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)). Each Handler has its own name-space for message codes, so you do not need to worry about yours conflicting with other handlers.

<br />

|                                    Returns                                    ||
|-----------------------------------------------------------------------|--------|
| [Handler](https://developer.android.com/reference/android/os/Handler) | <br /> |

### getWhen

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public long getWhen ()
```

Return the targeted delivery time of this message, in milliseconds.

<br />

|    Returns     ||
|--------|--------|
| `long` | <br /> |

### isAsynchronous

Added in[API level 22](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isAsynchronous ()
```

Returns true if the message is asynchronous, meaning that it is not subject to[Looper](https://developer.android.com/reference/android/os/Looper)synchronization barriers.

<br />

|                        Returns                         ||
|-----------|---------------------------------------------|
| `boolean` | True if the message is asynchronous. <br /> |

**See also:**

- [setAsynchronous(boolean)](https://developer.android.com/reference/android/os/Message#setAsynchronous(boolean))  

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the value for the*target*member on the Message returned.

<br />

|                                        Parameters                                         ||
|-----|--------------------------------------------------------------------------------------|
| `h` | `Handler`: Handler to assign to the returned Message object's*target* member. <br /> |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h, 
                int what)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values for both*target* and*what*members on the Message.

<br />

|                            Parameters                            ||
|--------|----------------------------------------------------------|
| `h`    | `Handler`: Value to assign to the*target* member. <br /> |
| `what` | `int`: Value to assign to the*what* member. <br />       |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h, 
                Runnable callback)
```

Same as[obtain(android.os.Handler)](https://developer.android.com/reference/android/os/Message#obtain(android.os.Handler)), but assigns a callback Runnable on the Message that is returned.

<br />

|                                            Parameters                                            ||
|------------|--------------------------------------------------------------------------------------|
| `h`        | `Handler`: Handler to assign to the returned Message object's*target* member. <br /> |
| `callback` | `Runnable`: Runnable that will execute when the message is handled. <br />           |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Message orig)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but copies the values of an existing message (including its target) into the new one.

<br />

|                     Parameters                      ||
|--------|---------------------------------------------|
| `orig` | `Message`: Original message to copy. <br /> |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h, 
                int what, 
                int arg1, 
                int arg2, 
                Object obj)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* ,*arg1* ,*arg2* , and*obj*members.

<br />

|                     Parameters                      ||
|--------|---------------------------------------------|
| `h`    | `Handler`: The*target* value to set. <br /> |
| `what` | `int`: The*what* value to set. <br />       |
| `arg1` | `int`: The*arg1* value to set. <br />       |
| `arg2` | `int`: The*arg2* value to set. <br />       |
| `obj`  | `Object`: The*obj* value to set. <br />     |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h, 
                int what, 
                int arg1, 
                int arg2)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* ,*arg1* , and*arg2*members.

<br />

|                     Parameters                      ||
|--------|---------------------------------------------|
| `h`    | `Handler`: The*target* value to set. <br /> |
| `what` | `int`: The*what* value to set. <br />       |
| `arg1` | `int`: The*arg1* value to set. <br />       |
| `arg2` | `int`: The*arg2* value to set. <br />       |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain (Handler h, 
                int what, 
                Object obj)
```

Same as[obtain()](https://developer.android.com/reference/android/os/Message#obtain()), but sets the values of the*target* ,*what* , and*obj*members.

<br />

|                     Parameters                      ||
|--------|---------------------------------------------|
| `h`    | `Handler`: The*target* value to set. <br /> |
| `what` | `int`: The*what* value to set. <br />       |
| `obj`  | `Object`: The*object* method to set. <br /> |

|                                                       Returns                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------|
| [Message](https://developer.android.com/reference/android/os/Message) | A Message object from the global pool. <br /> |

### obtain

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Message obtain ()
```

Return a new Message instance from the global pool. Allows us to avoid allocating new objects in many cases.

<br />

|                                    Returns                                    ||
|-----------------------------------------------------------------------|--------|
| [Message](https://developer.android.com/reference/android/os/Message) | <br /> |

### peekData

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Bundle peekData ()
```

Like getData(), but does not lazily create the Bundle. A null is returned if the Bundle does not already exist. See[getData()](https://developer.android.com/reference/android/os/Message#getData())for further information on this.

<br />

|                                   Returns                                   ||
|---------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle) | <br /> |

**See also:**

- [getData()](https://developer.android.com/reference/android/os/Message#getData())
- [setData(Bundle)](https://developer.android.com/reference/android/os/Message#setData(android.os.Bundle))  

### recycle

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void recycle ()
```

Return a Message instance to the global pool.

You MUST NOT touch the Message after calling this function because it has effectively been freed. It is an error to recycle a message that is currently enqueued or that is in the process of being delivered to a Handler.

<br />

<br />

### sendToTarget

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendToTarget ()
```

Sends this Message to the Handler specified by[getTarget()](https://developer.android.com/reference/android/os/Message#getTarget()). Throws a null pointer exception if this field has not been set.

<br />

### setAsynchronous

Added in[API level 22](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setAsynchronous (boolean async)
```

Sets whether the message is asynchronous, meaning that it is not subject to[Looper](https://developer.android.com/reference/android/os/Looper)synchronization barriers.

Certain operations, such as view invalidation, may introduce synchronization barriers into the[Looper](https://developer.android.com/reference/android/os/Looper)'s message queue to prevent subsequent messages from being delivered until some condition is met. In the case of view invalidation, messages which are posted after a call to[View.invalidate()](https://developer.android.com/reference/android/view/View#invalidate())are suspended by means of a synchronization barrier until the next frame is ready to be drawn. The synchronization barrier ensures that the invalidation request is completely handled before resuming.

Asynchronous messages are exempt from synchronization barriers. They typically represent interrupts, input events, and other signals that must be handled independently even while other work has been suspended.

Note that asynchronous messages may be delivered out of order with respect to synchronous messages although they are always delivered in order among themselves. If the relative order of these messages matters then they probably should not be asynchronous in the first place. Use with caution.

<br />

<br />

|                           Parameters                            ||
|---------|--------------------------------------------------------|
| `async` | `boolean`: True if the message is asynchronous. <br /> |

**See also:**

- [isAsynchronous()](https://developer.android.com/reference/android/os/Message#isAsynchronous())  

### setData

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setData (Bundle data)
```

Sets a Bundle of arbitrary data values. Use arg1 and arg2 members as a lower cost way to send a few simple integer values, if you can.

<br />

|       Parameters        ||
|--------|-----------------|
| `data` | `Bundle` <br /> |

**See also:**

- [getData()](https://developer.android.com/reference/android/os/Message#getData())
- [peekData()](https://developer.android.com/reference/android/os/Message#peekData())  

### setTarget

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setTarget (Handler target)
```

<br />

<br />

|         Parameters         ||
|----------|------------------|
| `target` | `Handler` <br /> |

### toString

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Returns a string representation of the object.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |

### writeToParcel

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

|                                                                                                                                                                                                                               Parameters                                                                                                                                                                                                                                ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dest`  | `Parcel`: The Parcel in which the object should be written. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                 |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or[Parcelable.PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE). Value is either`0`or a combination of[Parcelable.PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE), and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES <br /> |