AndroidUiDispatcher


A CoroutineDispatcher that will perform dispatch during a handler callback or choreographer's animation frame stage, whichever comes first. Use Main to obtain a dispatcher for the process's main thread (i.e. the activity thread) or CurrentThread to obtain a dispatcher for the current thread.

Summary

Public companion functions

Unit

Removes the tracer installed by setTracer, if any.

android
Unit

Specifies a tracer that instruments task dispatch and frame callbacks.

android

Public companion properties

CoroutineContext

The canonical CoroutineContext containing the AndroidUiDispatcher and its frameClock for the calling thread.

android
CoroutineContext

The CoroutineContext containing the AndroidUiDispatcher and its frameClock for the process's main thread.

android

Public functions

open Unit
dispatch(context: CoroutineContext, block: Runnable)
android

Public properties

Choreographer
android
MonotonicFrameClock

A MonotonicFrameClock associated with this AndroidUiDispatcher's choreographer that may be used to await Choreographer frame dispatch.

android

Inherited functions

From kotlin.coroutines.CoroutineContext
open operator CoroutineContext
android
From kotlin.coroutines.CoroutineContext.Element
open R
<R : Any?> fold(initial: R, operation: (CoroutineContext.Element, R) -> R)
android
open operator E?
android
open CoroutineContext
android
From kotlinx.coroutines.CoroutineDispatcher
open Unit
android
final Continuation<T>
<T : Any?> interceptContinuation(continuation: Continuation<T>)
android
open Boolean
android
open CoroutineDispatcher
limitedParallelism(parallelism: Int, name: String?)
android
operator CoroutineDispatcher

This function is deprecated. Operator '+' on two CoroutineDispatcher objects is meaningless.

android
final Unit
android
open String
android

Public companion functions

removeTracer

fun removeTracer(): Unit

Removes the tracer installed by setTracer, if any.

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

setTracer

fun setTracer(tracer: UiDispatcherTracer): Unit

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.

Public companion properties

CurrentThread

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.

Main

val Main: CoroutineContext

The CoroutineContext containing the AndroidUiDispatcher and its frameClock for the process's main thread.

Public functions

dispatch

open fun dispatch(context: CoroutineContext, block: Runnable): Unit

Public properties

choreographer

val choreographer: Choreographer

frameClock

val frameClock: MonotonicFrameClock

A MonotonicFrameClock associated with this AndroidUiDispatcher's choreographer that may be used to await Choreographer frame dispatch.