Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

HandlerCompat

class HandlerCompat
kotlin.Any
   ↳ androidx.core.os.HandlerCompat

Helper for accessing features in Handler.

Summary

Public methods
static Handler
createAsync(@NonNull looper: Looper)

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

static Handler
createAsync(@NonNull looper: Looper, @NonNull callback: Callback)

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

static Boolean
postDelayed(@NonNull handler: Handler, @NonNull r: Runnable, @Nullable token: Any?, delayMillis: Long)

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Public methods

createAsync

@NonNull static fun createAsync(@NonNull looper: Looper): Handler

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

Messages sent to an async handler are guaranteed to be ordered with respect to one another, but not necessarily with respect to messages from other Handlers.

Parameters
looper Looper: the Looper that the new Handler should be bound to
Return
Handler: a new async Handler instance

createAsync

@NonNull static fun createAsync(@NonNull looper: Looper, @NonNull callback: Callback): Handler

Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync.

Messages sent to an async handler are guaranteed to be ordered with respect to one another, but not necessarily with respect to messages from other Handlers.

Parameters
looper Looper: the Looper that the new Handler should be bound to
Return
Handler: a new async Handler instance

postDelayed

static fun postDelayed(@NonNull handler: Handler, @NonNull r: Runnable, @Nullable token: Any?, delayMillis: Long): Boolean

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the thread to which this handler is attached. The time-base is android.os.SystemClock#uptimeMillis. Time spent in deep sleep will add an additional delay to execution.

Parameters
r Handler: The Runnable that will be executed.
token Handler: An instance which can be used to cancel r via Handler#removeCallbacksAndMessages.
delayMillis Handler: The delay (in milliseconds) until the Runnable will be executed.
Return
Boolean: Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.