Added in API level 26

TestLooperManager


open class TestLooperManager
kotlin.Any
   ↳ android.os.TestLooperManager

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 android.app.Instrumentation#acquireLooperManager. Until release() is called, the Looper thread will not execute any messages except when execute(android.os.Message) is called. The test code may use next() to acquire messages that have been queued to this Looper/MessageQueue and then execute to run any that desires.

Summary

Public methods
open Unit
execute(message: Message!)

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

open MessageQueue!

Returns the MessageQueue this object is wrapping.

open Boolean
hasMessages(h: Handler!, object: Any!, what: Int)

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

open Boolean
hasMessages(h: Handler!, object: Any!, r: Runnable!)

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

open Message!

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

open Unit

Called to indicate that a Message returned by next() has been parsed and should be recycled.

open Unit

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

Public methods

execute

Added in API level 26
open fun execute(message: Message!): Unit

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.

getMessageQueue

Added in API level 26
open fun getMessageQueue(): MessageQueue!

Returns the MessageQueue this object is wrapping.

hasMessages

Added in API level 26
open fun hasMessages(
    h: Handler!,
    object: Any!,
    what: Int
): Boolean

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

Parameters
h Handler!: the value of Message#getTarget()
what Int: the value of Message#what
object Any!: the value of Message#obj, null for any

hasMessages

Added in API level 26
open fun hasMessages(
    h: Handler!,
    object: Any!,
    r: Runnable!
): Boolean

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

Parameters
h Handler!: the value of Message#getTarget()
r Runnable!: the value of Message#getCallback()
object Any!: the value of Message#obj, null for any

next

Added in API level 26
open fun next(): Message!

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

Callers should always call recycle(android.os.Message) on the message when all interactions with it have completed.

recycle

Added in API level 26
open fun recycle(msg: Message!): Unit

Called to indicate that a Message returned by next() has been parsed and should be recycled.

release

Added in API level 26
open fun release(): Unit

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