Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/os/TestLooperManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/TestLooperManager#inhmethods)

# TestLooperManager

*** ** * ** ***

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


`
public


class
TestLooperManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

Blocks a looper from executing any messages, and allows the holder of this object
to control when and which messages get executed until it is released.


A TestLooperManager should be acquired using
`https://developer.android.com/reference/android/app/Instrumentation#acquireLooperManager(android.os.Looper)`. Until `https://developer.android.com/reference/android/os/TestLooperManager#release()` is called,
the Looper thread will not execute any messages except when `https://developer.android.com/reference/android/os/TestLooperManager#execute(android.os.Message)` is called.
The test code may use `https://developer.android.com/reference/android/os/TestLooperManager#next()` to acquire messages that have been queued to this
`https://developer.android.com/reference/android/os/Looper`/`https://developer.android.com/reference/android/os/MessageQueue` and then `https://developer.android.com/reference/android/os/TestLooperManager#execute(android.os.Message)` to run any that desires.

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/os/TestLooperManager#execute(android.os.Message)(https://developer.android.com/reference/android/os/Message message) ` Executes the given message on the Looper thread this wrapper is attached to. |
| ` https://developer.android.com/reference/android/os/MessageQueue` | ` https://developer.android.com/reference/android/os/TestLooperManager#getMessageQueue()() ` Returns the `https://developer.android.com/reference/android/os/MessageQueue` this object is wrapping. |
| ` boolean` | ` https://developer.android.com/reference/android/os/TestLooperManager#hasMessages(android.os.Handler,%20java.lang.Object,%20java.lang.Runnable)(https://developer.android.com/reference/android/os/Handler h, https://developer.android.com/reference/java/lang/Object object, https://developer.android.com/reference/java/lang/Runnable r) ` Returns true if there are any queued messages that match the parameters. |
| ` boolean` | ` https://developer.android.com/reference/android/os/TestLooperManager#hasMessages(android.os.Handler,%20java.lang.Object,%20int)(https://developer.android.com/reference/android/os/Handler h, https://developer.android.com/reference/java/lang/Object object, int what) ` Returns true if there are any queued messages that match the parameters. |
| ` boolean` | ` https://developer.android.com/reference/android/os/TestLooperManager#isBlockedOnSyncBarrier()() ` Checks whether the Looper is currently blocked on a sync barrier. |
| ` https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/TestLooperManager#next()() ` Returns the next message that should be executed by this queue, may block if no messages are ready. |
| ` https://developer.android.com/reference/java/lang/Long` | ` https://developer.android.com/reference/android/os/TestLooperManager#peekWhen()() ` Retrieves, but does not remove, the values of `https://developer.android.com/` of next message in the queue. |
| ` https://developer.android.com/reference/android/os/Message` | ` https://developer.android.com/reference/android/os/TestLooperManager#poll()() ` Retrieves and removes the next message in this queue. |
| ` void` | ` https://developer.android.com/reference/android/os/TestLooperManager#recycle(android.os.Message)(https://developer.android.com/reference/android/os/Message msg) ` Called to indicate that a Message returned by `https://developer.android.com/reference/android/os/TestLooperManager#next()` has been parsed and should be recycled. |
| ` void` | ` https://developer.android.com/reference/android/os/TestLooperManager#release()() ` Releases the looper to continue standard looping and processing of messages, no further interactions with TestLooperManager will be allowed after release() has been called. |

| ### 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 methods

### execute

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

```
public void execute (Message message)
```

Executes the given message on the Looper thread this wrapper is
attached to.


Execution will happen on the Looper's thread (whether it is the current thread
or not), but all RuntimeExceptions encountered while executing the message will
be thrown on the calling thread.

<br />

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

### getMessageQueue

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

```
public MessageQueue getMessageQueue ()
```

Returns the `https://developer.android.com/reference/android/os/MessageQueue` this object is wrapping.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/MessageQueue` | <br /> |

### hasMessages

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

```
public boolean hasMessages (Handler h, 
                Object object, 
                Runnable r)
```

Returns true if there are any queued messages that match the parameters.

<br />

| Parameters ||
|---|---|
| `h` | `Handler`: the value of `https://developer.android.com/reference/android/os/Message#getTarget()` <br /> |
| `object` | `Object`: the value of `https://developer.android.com/reference/android/os/Message#obj`, null for any <br /> |
| `r` | `Runnable`: the value of `https://developer.android.com/reference/android/os/Message#getCallback()` <br /> |

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

### hasMessages

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

```
public boolean hasMessages (Handler h, 
                Object object, 
                int what)
```

Returns true if there are any queued messages that match the parameters.

<br />

| Parameters ||
|---|---|
| `h` | `Handler`: the value of `https://developer.android.com/reference/android/os/Message#getTarget()` <br /> |
| `object` | `Object`: the value of `https://developer.android.com/reference/android/os/Message#obj`, null for any <br /> |
| `what` | `int`: the value of `https://developer.android.com/reference/android/os/Message#what` <br /> |

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

### isBlockedOnSyncBarrier

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

```
public boolean isBlockedOnSyncBarrier ()
```

Checks whether the Looper is currently blocked on a sync barrier.

<br />

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

### next

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

```
public Message next ()
```

Returns the next message that should be executed by this queue, may block
if no messages are ready.


Callers should always call `https://developer.android.com/reference/android/os/TestLooperManager#recycle(android.os.Message)` on the message when all
interactions with it have completed.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | <br /> |

### peekWhen

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

```
public Long peekWhen ()
```

Retrieves, but does not remove, the values of `https://developer.android.com/` of next message in the
queue.
If the queue is empty, returns null.
This method never blocks.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Long` | <br /> |

### poll

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

```
public Message poll ()
```

Retrieves and removes the next message in this queue.
If the queue is empty, returns null.
This method never blocks.

Callers should always call `https://developer.android.com/reference/android/os/TestLooperManager#recycle(android.os.Message)` on the message when all interactions
with it have completed.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Message` | <br /> |

### recycle

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

```
public void recycle (Message msg)
```

Called to indicate that a Message returned by `https://developer.android.com/reference/android/os/TestLooperManager#next()` has been parsed
and should be recycled.

<br />

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

### release

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

```
public void release ()
```

Releases the looper to continue standard looping and processing of messages, no further
interactions with TestLooperManager will be allowed after release() has been called.

<br />