public class AndroidUiDispatcher private constructor(
public val choreographer: Choreographer,
private val handler: android.os.Handler,
) : CoroutineDispatcher()
Properties
frameClock
public val frameClock: MonotonicFrameClock = AndroidUiFrameClock(choreographer, this)
A MonotonicFrameClock associated with this AndroidUiDispatcher's choreographer that may be used to await Choreographer frame dispatch.
Functions
dispatch
override fun dispatch(context: CoroutineContext, block: Runnable)
Members
Companion
public companion object
Properties
Main
public val Main: CoroutineContext by
lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
val dispatcher =
AndroidUiDispatcher(
if (isMainThread()) Choreographer.getInstance()
else runBlocking(Dispatchers.Main) { Choreographer.getInstance() },
HandlerCompat.createAsync(Looper.getMainLooper()),
)
dispatcher + dispatcher.frameClock
}
The CoroutineContext containing the AndroidUiDispatcher and its frameClock for the process's main thread.
CurrentThread
public val CurrentThread: CoroutineContext
The canonical CoroutineContext containing the AndroidUiDispatcher and its frameClock for the calling thread. Returns Main if accessed from the process's main thread.
Throws IllegalStateException if the calling thread does not have both a Choreographer and an active Looper.
Functions
setTracer
public fun setTracer(tracer: UiDispatcherTracer)
Specifies a tracer that instruments task dispatch and frame callbacks. The tracer is global: it applies to every AndroidUiDispatcher instance in the process, and replaces any tracer installed earlier. Call removeTracer to stop tracing.
The dispatcher reads the tracer without synchronization, so a change may not reach other threads immediately and may miss events already in flight.
removeTracer
public fun removeTracer()
Removes the tracer installed by setTracer, if any.
As with setTracer, other threads may not see the change immediately.