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

# Handler

*** ** * ** ***

` public class Handler `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

Known direct subclasses [AsyncQueryHandler](https://developer.android.com/reference/android/content/AsyncQueryHandler), [AsyncQueryHandler.WorkerHandler](https://developer.android.com/reference/android/content/AsyncQueryHandler.WorkerHandler), [HttpAuthHandler](https://developer.android.com/reference/android/webkit/HttpAuthHandler), [SslErrorHandler](https://developer.android.com/reference/android/webkit/SslErrorHandler) [AsyncQueryHandler](https://developer.android.com/reference/android/content/AsyncQueryHandler) A helper class to help make handling asynchronous `https://developer.android.com/reference/android/content/ContentResolver` queries easier. [AsyncQueryHandler.WorkerHandler](https://developer.android.com/reference/android/content/AsyncQueryHandler.WorkerHandler) [HttpAuthHandler](https://developer.android.com/reference/android/webkit/HttpAuthHandler) Represents a request for HTTP authentication. [SslErrorHandler](https://developer.android.com/reference/android/webkit/SslErrorHandler) Represents a request for handling an SSL error.   

*** ** * ** ***

A Handler allows you to send and process `https://developer.android.com/reference/android/os/Message` and Runnable objects associated with a thread's `https://developer.android.com/reference/android/os/MessageQueue`. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler it is bound to a `https://developer.android.com/reference/android/os/Looper`. It will deliver messages and runnables to that Looper's message queue and execute them on that Looper's thread.

There are two main uses for a Handler: (1) to schedule messages and runnables to be executed at some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.

Scheduling messages is accomplished with the `https://developer.android.com/reference/android/os/Handler#post(java.lang.Runnable)`, `https://developer.android.com/reference/android/os/Handler#postAtTime(java.lang.Runnable,%20long)`, `https://developer.android.com/reference/android/os/Handler#postDelayed(java.lang.Runnable,%20java.lang.Object,%20long)`, `https://developer.android.com/reference/android/os/Handler#sendEmptyMessage(int)`, `https://developer.android.com/reference/android/os/Handler#sendMessage(android.os.Message)`, `https://developer.android.com/reference/android/os/Handler#sendMessageAtTime(android.os.Message,%20long)`, and `https://developer.android.com/reference/android/os/Handler#sendMessageDelayed(android.os.Message,%20long)` methods. The *post* versions allow you to enqueue Runnable objects to be called by the message queue when they are received; the *sendMessage* versions allow you to enqueue a `https://developer.android.com/reference/android/os/Message` object containing a bundle of data that will be processed by the Handler's `https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)` method (requiring that you implement a subclass of Handler).

When posting or sending to a Handler, you can either allow the item to be processed as soon as the message queue is ready to do so, or specify a delay before it gets processed or absolute time for it to be processed. The latter two allow you to implement timeouts, ticks, and other timing-based behavior.

When a process is created for your application, its main thread is dedicated to running a message queue that takes care of managing the top-level application objects (activities, broadcast receivers, etc) and any windows they create. You can create your own threads, and communicate back with the main application thread through a Handler. This is done by calling the same *post* or *sendMessage* methods as before, but from your new thread. The given Runnable or Message will then be scheduled in the Handler's message queue and processed when appropriate.

## Performance considerations when using `Handler`

Beware that the "has" and "remove" methods of `Handler` can be very slow because these operations scan the entire queue of pending messages. If the underlying `https://developer.android.com/reference/android/os/Looper`'s `https://developer.android.com/reference/android/os/MessageQueue` has many pending messages, this can be expensive.

- Instead of removing a message or a callback to cancel a pending operation, consider setting a flag to indicate cancellation and having the operation check the flag before proceeding.
- Instead of checking if the queue has a message or a callback to find if a pending operation has not yet occurred, consider having that operation set a flag to indicate that it has begun.

See `java.util.concurrent` for standard concurrency primitives.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/os/Handler.Callback` Callback interface you can use when instantiating a Handler to avoid having to implement your own subclass of Handler. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/os/Handler#Handler()() ` *This constructor is deprecated. Implicitly choosing a Looper during Handler construction can lead to bugs where operations are silently lost (if the Handler is not expecting new tasks and quits), crashes (if a handler is sometimes created on a thread without a Looper active), or race conditions, where the thread a handler is associated with is not what the author anticipated. Instead, use an `https://developer.android.com/reference/java/util/concurrent/Executor` or specify the Looper explicitly, using `https://developer.android.com/reference/android/os/Looper#getMainLooper()`, `https://developer.android.com/reference/android/view/View#getHandler()`, or similar. If the implicit thread local behavior is required for compatibility, use `new Handler(Looper.myLooper())` to make it clear to readers.* |
| ` https://developer.android.com/reference/android/os/Handler#Handler(android.os.Handler.Callback)(https://developer.android.com/reference/android/os/Handler.Callback callback) ` *This constructor is deprecated. Implicitly choosing a Looper during Handler construction can lead to bugs where operations are silently lost (if the Handler is not expecting new tasks and quits), crashes (if a handler is sometimes created on a thread without a Looper active), or race conditions, where the thread a handler is associated with is not what the author anticipated. Instead, use an `https://developer.android.com/reference/java/util/concurrent/Executor` or specify the Looper explicitly, using `https://developer.android.com/reference/android/os/Looper#getMainLooper()`, `https://developer.android.com/reference/android/view/View#getHandler()`, or similar. If the implicit thread local behavior is required for compatibility, use `new Handler(Looper.myLooper(), callback)` to make it clear to readers.* |
| ` https://developer.android.com/reference/android/os/Handler#Handler(android.os.Looper)(https://developer.android.com/reference/android/os/Looper looper) ` Use the provided `https://developer.android.com/reference/android/os/Looper` instead of the default one. |
| ` https://developer.android.com/reference/android/os/Handler#Handler(android.os.Looper,%20android.os.Handler.Callback)(https://developer.android.com/reference/android/os/Looper looper, https://developer.android.com/reference/android/os/Handler.Callback callback) ` Use the provided `https://developer.android.com/reference/android/os/Looper` instead of the default one and take a callback interface in which to handle messages. |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/os/Handler` | ` https://developer.android.com/reference/android/os/Handler#createAsync(android.os.Looper,%20android.os.Handler.Callback)(https://developer.android.com/reference/android/os/Looper looper, https://developer.android.com/reference/android/os/Handler.Callback callback) ` Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync. |
| ` static https://developer.android.com/reference/android/os/Handler` | ` https://developer.android.com/reference/android/os/Handler#createAsync(android.os.Looper)(https://developer.android.com/reference/android/os/Looper looper) ` Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync. |
| ` void` | ` https://developer.android.com/reference/android/os/Handler#dispatchMessage(android.os.Message)(https://developer.android.com/reference/android/os/Message msg) ` Handle system messages here. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#dump(android.util.Printer,%20java.lang.String)(https://developer.android.com/reference/android/util/Printer pw, https://developer.android.com/reference/java/lang/String prefix) ` |
| ` final https://developer.android.com/reference/android/os/Looper` | ` https://developer.android.com/reference/android/os/Handler#getLooper()() ` |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/os/Handler#getMessageName(android.os.Message)(https://developer.android.com/reference/android/os/Message message) ` Returns a string representing the name of the specified message. |
| ` void` | ` https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)(https://developer.android.com/reference/android/os/Message msg) ` Subclasses must implement this to receive messages. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#hasCallbacks(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable r) ` Check if there are any pending posts of messages with callback r in the message queue. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#hasMessages(int)(int what) ` Check if there are any pending posts of messages with code 'what' in the message queue. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#hasMessages(int,%20java.lang.Object)(int what, https://developer.android.com/reference/java/lang/Object object) ` Check if there are any pending posts of messages with code 'what' and whose obj is 'object' in the message queue. |
| ` final https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/Handler#obtainMessage(int,%20java.lang.Object)(int what, https://developer.android.com/reference/java/lang/Object obj) ` Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what and obj members of the returned Message. |
| ` final https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/Handler#obtainMessage()() ` Returns a new `https://developer.android.com/reference/android/os/Message` from the global message pool. |
| ` final https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/Handler#obtainMessage(int,%20int,%20int)(int what, int arg1, int arg2) ` Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what, arg1 and arg2 members of the returned Message. |
| ` final https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/Handler#obtainMessage(int,%20int,%20int,%20java.lang.Object)(int what, int arg1, int arg2, https://developer.android.com/reference/java/lang/Object obj) ` Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what, obj, arg1,and arg2 values on the returned Message. |
| ` final https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/Handler#obtainMessage(int)(int what) ` Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what member of the returned Message. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#post(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable r) ` Causes the Runnable r to be added to the message queue. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#postAtFrontOfQueue(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable r) ` Posts a message to an object that implements Runnable. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#postAtTime(java.lang.Runnable,%20long)(https://developer.android.com/reference/java/lang/Runnable r, long uptimeMillis) ` Causes the Runnable r to be added to the message queue, to be run at a specific time given by <var translate="no">uptimeMillis</var>. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#postAtTime(java.lang.Runnable,%20java.lang.Object,%20long)(https://developer.android.com/reference/java/lang/Runnable r, https://developer.android.com/reference/java/lang/Object token, long uptimeMillis) ` Causes the Runnable r to be added to the message queue, to be run at a specific time given by <var translate="no">uptimeMillis</var>. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#postDelayed(java.lang.Runnable,%20long)(https://developer.android.com/reference/java/lang/Runnable r, long delayMillis) ` Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#postDelayed(java.lang.Runnable,%20java.lang.Object,%20long)(https://developer.android.com/reference/java/lang/Runnable r, https://developer.android.com/reference/java/lang/Object token, long delayMillis) ` Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#removeCallbacks(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable r) ` Remove any pending posts of Runnable r that are in the message queue. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#removeCallbacks(java.lang.Runnable,%20java.lang.Object)(https://developer.android.com/reference/java/lang/Runnable r, https://developer.android.com/reference/java/lang/Object token) ` Remove any pending posts of Runnable <var translate="no">r</var> with Object <var translate="no">token</var> that are in the message queue. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#removeCallbacksAndMessages(java.lang.Object)(https://developer.android.com/reference/java/lang/Object token) ` Remove any pending posts of callbacks and sent messages whose <var translate="no">obj</var> is <var translate="no">token</var>. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#removeMessages(int)(int what) ` Remove any pending posts of messages with code 'what' that are in the message queue. |
| ` final void` | ` https://developer.android.com/reference/android/os/Handler#removeMessages(int,%20java.lang.Object)(int what, https://developer.android.com/reference/java/lang/Object object) ` Remove any pending posts of messages with code 'what' and whose obj is 'object' that are in the message queue. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendEmptyMessage(int)(int what) ` Sends a Message containing only the what value. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendEmptyMessageAtTime(int,%20long)(int what, long uptimeMillis) ` Sends a Message containing only the what value, to be delivered at a specific time. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendEmptyMessageDelayed(int,%20long)(int what, long delayMillis) ` Sends a Message containing only the what value, to be delivered after the specified amount of time elapses. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendMessage(android.os.Message)(https://developer.android.com/reference/android/os/Message msg) ` Pushes a message onto the end of the message queue after all pending messages before the current time. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendMessageAtFrontOfQueue(android.os.Message)(https://developer.android.com/reference/android/os/Message msg) ` Enqueue a message at the front of the message queue, to be processed on the next iteration of the message loop. |
| ` boolean` | ` https://developer.android.com/reference/android/os/Handler#sendMessageAtTime(android.os.Message,%20long)(https://developer.android.com/reference/android/os/Message msg, long uptimeMillis) ` Enqueue a message into the message queue after all pending messages before the absolute time (in milliseconds) <var translate="no">uptimeMillis</var>. |
| ` final boolean` | ` https://developer.android.com/reference/android/os/Handler#sendMessageDelayed(android.os.Message,%20long)(https://developer.android.com/reference/android/os/Message msg, long delayMillis) ` Enqueue a message into the message queue after all pending messages before (current time + delayMillis). |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/os/Handler#toString()() ` Returns a string representation of the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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*.

## Public constructors

### Handler

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

```
public Handler ()
```

<br />

**This constructor is deprecated.**   

Implicitly choosing a Looper during Handler construction can lead to bugs where operations are silently lost (if the Handler is not expecting new tasks and quits), crashes (if a handler is sometimes created on a thread without a Looper active), or race conditions, where the thread a handler is associated with is not what the author anticipated. Instead, use an `https://developer.android.com/reference/java/util/concurrent/Executor` or specify the Looper explicitly, using `https://developer.android.com/reference/android/os/Looper#getMainLooper()`, `https://developer.android.com/reference/android/view/View#getHandler()`, or similar. If the implicit thread local behavior is required for compatibility, use `new Handler(Looper.myLooper())` to make it clear to readers.

Default constructor associates this handler with the `https://developer.android.com/reference/android/os/Looper` for the current thread. If this thread does not have a looper, this handler won't be able to receive messages so an exception is thrown.

<br />

### Handler

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

```
public Handler (Handler.Callback callback)
```

<br />

**This constructor is deprecated.**   

Implicitly choosing a Looper during Handler construction can lead to bugs where operations are silently lost (if the Handler is not expecting new tasks and quits), crashes (if a handler is sometimes created on a thread without a Looper active), or race conditions, where the thread a handler is associated with is not what the author anticipated. Instead, use an `https://developer.android.com/reference/java/util/concurrent/Executor` or specify the Looper explicitly, using `https://developer.android.com/reference/android/os/Looper#getMainLooper()`, `https://developer.android.com/reference/android/view/View#getHandler()`, or similar. If the implicit thread local behavior is required for compatibility, use `new Handler(Looper.myLooper(), callback)` to make it clear to readers.

Constructor associates this handler with the `https://developer.android.com/reference/android/os/Looper` for the current thread and takes a callback interface in which you can handle messages. If this thread does not have a looper, this handler won't be able to receive messages so an exception is thrown.

<br />

| Parameters ||
|---|---|
| `callback` | `Handler.Callback`: The callback interface in which to handle messages, or null. <br /> |

### Handler

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

```
public Handler (Looper looper)
```

Use the provided `https://developer.android.com/reference/android/os/Looper` instead of the default one.

<br />

| Parameters ||
|---|---|
| `looper` | `Looper`: The looper, must not be null. <br /> |

### Handler

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

```
public Handler (Looper looper, 
                Handler.Callback callback)
```

Use the provided `https://developer.android.com/reference/android/os/Looper` instead of the default one and take a callback interface in which to handle messages.

<br />

| Parameters ||
|---|---|
| `looper` | `Looper`: The looper, must not be null. <br /> |
| `callback` | `Handler.Callback`: The callback interface in which to handle messages, or null. <br /> |

## Public methods

### createAsync

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

```
public static Handler createAsync (Looper looper, 
                Handler.Callback callback)
```

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

Messages sent to an async handler are guaranteed to be ordered with respect to one another, but not necessarily with respect to messages from other Handlers.

<br />

<br />

| Parameters ||
|---|---|
| `looper` | `Looper`: the Looper that the new Handler should be bound to. This value cannot be `null`. <br /> |
| `callback` | `Handler.Callback`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Handler` | a new async Handler instance. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Handler#createAsync(android.os.Looper)`

### createAsync

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

```
public static Handler createAsync (Looper looper)
```

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

Messages sent to an async handler are guaranteed to be ordered with respect to one another, but not necessarily with respect to messages from other Handlers.

<br />

<br />

| Parameters ||
|---|---|
| `looper` | `Looper`: the Looper that the new Handler should be bound to. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Handler` | a new async Handler instance. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Handler#createAsync(android.os.Looper,%20android.os.Handler.Callback)`

### dispatchMessage

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

```
public void dispatchMessage (Message msg)
```

Handle system messages here.

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |

### dump

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

```
public final void dump (Printer pw, 
                String prefix)
```

<br />

<br />

| Parameters ||
|---|---|
| `pw` | `Printer`: This value cannot be `null`. <br /> |
| `prefix` | `String`: This value cannot be `null`. <br /> |

### getLooper

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

```
public final Looper getLooper ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Looper` | This value cannot be `null`. <br /> |

### getMessageName

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

```
public String getMessageName (Message message)
```

Returns a string representing the name of the specified message. The default implementation will either return the class name of the message callback if any, or the hexadecimal representation of the message "what" field.

<br />

| Parameters ||
|---|---|
| `message` | `Message`: The message whose name is being queried. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### handleMessage

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

```
public void handleMessage (Message msg)
```

Subclasses must implement this to receive messages.

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |

### hasCallbacks

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

```
public final boolean hasCallbacks (Runnable r)
```

Check if there are any pending posts of messages with callback r in the message queue.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to track if messages were enqueued and dispatched. For instance, maintain a counter, incrementing it when enqueuing a message and decrementing it when handling a message.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: This value cannot be `null`. <br /> |

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

### hasMessages

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

```
public final boolean hasMessages (int what)
```

Check if there are any pending posts of messages with code 'what' in the message queue.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to track if messages were enqueued and dispatched. For instance, maintain a counter, incrementing it when enqueuing a message and decrementing it when handling a message.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |

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

### hasMessages

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

```
public final boolean hasMessages (int what, 
                Object object)
```

Check if there are any pending posts of messages with code 'what' and whose obj is 'object' in the message queue.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to track if messages were enqueued and dispatched. For instance, maintain a counter, incrementing it when enqueuing a message and decrementing it when handling a message.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |
| `object` | `Object`: This value may be `null`. <br /> |

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

### obtainMessage

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

```
public final Message obtainMessage (int what, 
                Object obj)
```

Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what and obj members of the returned Message.

<br />

| Parameters ||
|---|---|
| `what` | `int`: Value to assign to the returned Message.what field. <br /> |
| `obj` | `Object`: Value to assign to the returned Message.obj field. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | A Message from the global message pool. This value cannot be `null`. <br /> |

### obtainMessage

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

```
public final Message obtainMessage ()
```

Returns a new `https://developer.android.com/reference/android/os/Message` from the global message pool. More efficient than creating and allocating new instances. The retrieved message has its handler set to this instance (Message.target == this). If you don't want that facility, just call Message.obtain() instead.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | This value cannot be `null`. <br /> |

### obtainMessage

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

```
public final Message obtainMessage (int what, 
                int arg1, 
                int arg2)
```

Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what, arg1 and arg2 members of the returned Message.

<br />

| Parameters ||
|---|---|
| `what` | `int`: Value to assign to the returned Message.what field. <br /> |
| `arg1` | `int`: Value to assign to the returned Message.arg1 field. <br /> |
| `arg2` | `int`: Value to assign to the returned Message.arg2 field. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | A Message from the global message pool. This value cannot be `null`. <br /> |

### obtainMessage

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

```
public final Message obtainMessage (int what, 
                int arg1, 
                int arg2, 
                Object obj)
```

Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what, obj, arg1,and arg2 values on the returned Message.

<br />

| Parameters ||
|---|---|
| `what` | `int`: Value to assign to the returned Message.what field. <br /> |
| `arg1` | `int`: Value to assign to the returned Message.arg1 field. <br /> |
| `arg2` | `int`: Value to assign to the returned Message.arg2 field. <br /> |
| `obj` | `Object`: Value to assign to the returned Message.obj field. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | A Message from the global message pool. This value cannot be `null`. <br /> |

### obtainMessage

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

```
public final Message obtainMessage (int what)
```

Same as `https://developer.android.com/reference/android/os/Handler#obtainMessage()`, except that it also sets the what member of the returned Message.

<br />

| Parameters ||
|---|---|
| `what` | `int`: Value to assign to the returned Message.what field. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | A Message from the global message pool. This value cannot be `null`. <br /> |

### post

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

```
public final boolean post (Runnable r)
```

Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

### postAtFrontOfQueue

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

```
public final boolean postAtFrontOfQueue (Runnable r)
```

Posts a message to an object that implements Runnable. Causes the Runnable r to executed on the next iteration through the message queue. The runnable will be run on the thread to which this handler is attached. **This method is only for use in very special circumstances -- it can easily starve the message queue, cause ordering problems, or have other unexpected side-effects.**

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

### postAtTime

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

```
public final boolean postAtTime (Runnable r, 
                long uptimeMillis)
```

Causes the Runnable r to be added to the message queue, to be run at a specific time given by <var translate="no">uptimeMillis</var>. **The time-base is `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`.** Time spent in deep sleep will add an additional delay to execution. The runnable will be run on the thread to which this handler is attached.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |
| `uptimeMillis` | `long`: The absolute time at which the callback should run, using the `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()` time-base. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <br /> |

### postAtTime

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

```
public final boolean postAtTime (Runnable r, 
                Object token, 
                long uptimeMillis)
```

Causes the Runnable r to be added to the message queue, to be run at a specific time given by <var translate="no">uptimeMillis</var>. **The time-base is `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`.** Time spent in deep sleep will add an additional delay to execution. The runnable will be run on the thread to which this handler is attached.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |
| `token` | `Object`: An instance which can be used to cancel `r` via `https://developer.android.com/reference/android/os/Handler#removeCallbacksAndMessages(java.lang.Object)`. This value may be `null`. <br /> |
| `uptimeMillis` | `long`: The absolute time at which the callback should run, using the `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()` time-base. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`

### postDelayed

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

```
public final boolean postDelayed (Runnable r, 
                long delayMillis)
```

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the thread to which this handler is attached. **The time-base is `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`.** Time spent in deep sleep will add an additional delay to execution.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |
| `delayMillis` | `long`: The delay (in milliseconds) until the Runnable will be executed. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <br /> |

### postDelayed

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

```
public final boolean postDelayed (Runnable r, 
                Object token, 
                long delayMillis)
```

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the thread to which this handler is attached. **The time-base is `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`.** Time spent in deep sleep will add an additional delay to execution.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: The Runnable that will be executed. This value cannot be `null`. <br /> |
| `token` | `Object`: An instance which can be used to cancel `r` via `https://developer.android.com/reference/android/os/Handler#removeCallbacksAndMessages(java.lang.Object)`. This value may be `null`. <br /> |
| `delayMillis` | `long`: The delay (in milliseconds) until the Runnable will be executed. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <br /> |

### removeCallbacks

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

```
public final void removeCallbacks (Runnable r)
```

Remove any pending posts of Runnable r that are in the message queue.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to cancel a pending operation. For instance, maintain a flag to indicate whether the operation should be performed differently or not at all once it is dispatched.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: This value cannot be `null`. <br /> |

### removeCallbacks

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

```
public final void removeCallbacks (Runnable r, 
                Object token)
```

Remove any pending posts of Runnable <var translate="no">r</var> with Object <var translate="no">token</var> that are in the message queue. If <var translate="no">token</var> is null, all callbacks will be removed.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to cancel a pending operation. For instance, maintain a flag to indicate whether the operation should be performed differently or not at all once it is dispatched.

<br />

| Parameters ||
|---|---|
| `r` | `Runnable`: This value cannot be `null`. <br /> |
| `token` | `Object`: This value may be `null`. <br /> |

### removeCallbacksAndMessages

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

```
public final void removeCallbacksAndMessages (Object token)
```

Remove any pending posts of callbacks and sent messages whose <var translate="no">obj</var> is <var translate="no">token</var>. If <var translate="no">token</var> is null, all callbacks and messages will be removed.

<br />

| Parameters ||
|---|---|
| `token` | `Object`: This value may be `null`. <br /> |

### removeMessages

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

```
public final void removeMessages (int what)
```

Remove any pending posts of messages with code 'what' that are in the message queue. Note that \`Message#what\` is 0 unless otherwise set. When calling \`postMessage(Runnable)\` or \`postAtTime(Runnable, long)\`, the \`Runnable\` is internally wrapped with a \`Message\` whose \`what\` is 0. Calling \`removeMessages(0)\` will remove all messages without a \`what\`, including posted \`Runnable\`s.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to cancel a pending operation. For instance, maintain a flag to indicate whether the operation should be performed differently or not at all once it is dispatched.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |

### removeMessages

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

```
public final void removeMessages (int what, 
                Object object)
```

Remove any pending posts of messages with code 'what' and whose obj is 'object' that are in the message queue. If <var translate="no">object</var> is null, all messages will be removed.

This operation is worst case O(n) in the number of messages in the queue, and should be avoided. Instead consider another mechanism outside of the queue to cancel a pending operation. For instance, maintain a flag to indicate whether the operation should be performed differently or not at all once it is dispatched.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |
| `object` | `Object`: This value may be `null`. <br /> |

### sendEmptyMessage

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

```
public final boolean sendEmptyMessage (int what)
```

Sends a Message containing only the what value.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

### sendEmptyMessageAtTime

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

```
public final boolean sendEmptyMessageAtTime (int what, 
                long uptimeMillis)
```

Sends a Message containing only the what value, to be delivered at a specific time.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |
| `uptimeMillis` | `long` <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Handler#sendMessageAtTime(android.os.Message,%20long)`

### sendEmptyMessageDelayed

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

```
public final boolean sendEmptyMessageDelayed (int what, 
                long delayMillis)
```

Sends a Message containing only the what value, to be delivered after the specified amount of time elapses.

<br />

| Parameters ||
|---|---|
| `what` | `int` <br /> |
| `delayMillis` | `long` <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Handler#sendMessageDelayed(android.os.Message,%20long)`

### sendMessage

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

```
public final boolean sendMessage (Message msg)
```

Pushes a message onto the end of the message queue after all pending messages before the current time. It will be received in `https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)`, in the thread attached to this handler.

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

### sendMessageAtFrontOfQueue

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

```
public final boolean sendMessageAtFrontOfQueue (Message msg)
```

Enqueue a message at the front of the message queue, to be processed on the next iteration of the message loop. You will receive it in `https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)`, in the thread attached to this handler. **This method is only for use in very special circumstances -- it can easily starve the message queue, cause ordering problems, or have other unexpected side-effects.**

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. <br /> |

### sendMessageAtTime

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

```
public boolean sendMessageAtTime (Message msg, 
                long uptimeMillis)
```

Enqueue a message into the message queue after all pending messages before the absolute time (in milliseconds) <var translate="no">uptimeMillis</var>. **The time-base is `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()`.** Time spent in deep sleep will add an additional delay to execution. You will receive it in `https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)`, in the thread attached to this handler.

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |
| `uptimeMillis` | `long`: The absolute time at which the message should be delivered, using the `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()` time-base. <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the message will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <br /> |

### sendMessageDelayed

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

```
public final boolean sendMessageDelayed (Message msg, 
                long delayMillis)
```

Enqueue a message into the message queue after all pending messages before (current time + delayMillis). You will receive it in `https://developer.android.com/reference/android/os/Handler#handleMessage(android.os.Message)`, in the thread attached to this handler.

<br />

| Parameters ||
|---|---|
| `msg` | `Message`: This value cannot be `null`. <br /> |
| `delayMillis` | `long` <br /> |

| Returns ||
|---|---|
| `boolean` | Returns true if the message was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the message will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. <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 ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |