Register now for Android Dev Summit 2019!

HandlerCompat

public final class HandlerCompat
extends Object

java.lang.Object
   ↳ androidx.core.os.HandlerCompat


Helper for accessing features in Handler.

Summary

Public methods

static Handler createAsync(Looper looper, Handler.Callback callback)

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

static Handler createAsync(Looper looper)

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

static boolean postDelayed(Handler handler, Runnable r, Object token, long delayMillis)

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

Inherited methods

Public methods

createAsync

public static Handler createAsync (Looper looper, 
                Handler.Callback callback)

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

callback Handler.Callback

Returns
Handler a new async Handler instance

createAsync

public static Handler createAsync (Looper looper)

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

Returns
Handler a new async Handler instance

postDelayed

public static boolean postDelayed (Handler handler, 
                Runnable r, 
                Object token, 
                long delayMillis)

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 SystemClock.uptimeMillis(). Time spent in deep sleep will add an additional delay to execution.

Parameters
handler Handler

r Runnable: The Runnable that will be executed.

token Object: An instance which can be used to cancel r via Handler.removeCallbacksAndMessages(Object).

delayMillis long: The delay (in milliseconds) until the Runnable will be executed.

Returns
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.