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 |
Executes the given message on the Looper thread this wrapper is attached to. |
open MessageQueue! |
Returns the |
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 Boolean |
Checks whether the Looper is currently blocked on a sync barrier. |
open Message! |
next() Returns the next message that should be executed by this queue, may block if no messages are ready. |
open Long? |
peekWhen() Retrieves, but does not remove, the values of android. |
open Message? |
poll() Retrieves and removes the next message that should be executed by this queue. |
open Unit |
Called to indicate that a Message returned by |
open Unit |
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. |
Public methods
execute
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
open fun getMessageQueue(): MessageQueue!
Returns the MessageQueue
this object is wrapping.
hasMessages
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
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 |
isBlockedOnSyncBarrier
open fun isBlockedOnSyncBarrier(): Boolean
Checks whether the Looper is currently blocked on a sync barrier.
next
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.
peekWhen
open fun peekWhen(): Long?
Retrieves, but does not remove, the values of android.os.Message#when of next message that should be executed by this queue. If the queue is empty or no messages are deliverable, returns null. This method never blocks.
poll
open fun poll(): Message?
Retrieves and removes the next message that should be executed by this queue. If the queue is empty or no messages are deliverable, returns null. This method never blocks.
Callers should always call recycle(android.os.Message)
on the message when all interactions with it have completed.
recycle
open fun recycle(msg: Message!): Unit
Called to indicate that a Message returned by next()
has been parsed and should be recycled.
release
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.