Class

AndroidUiDispatcher

Source set: Android
public class AndroidUiDispatcher private constructor(
    public val choreographer: Choreographer,
    private val handler: android.os.Handler,
) : CoroutineDispatcher()

Properties

frameClock

Source set: Android
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

Source set: Android
override fun dispatch(context: CoroutineContext, block: Runnable)

Members

Companion

Source set: Android
public companion object

Properties

Main

Source set: Android
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

Source set: Android
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

Source set: Android
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

Source set: Android
public fun removeTracer()

Removes the tracer installed by setTracer, if any.

As with setTracer, other threads may not see the change immediately.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: