core-ktx / androidx.os / android.os.Handler / postDelayed

postDelayed

fun Handler.postDelayed(runnable: Runnable, token: Any?, delayInMillis: Long): Unit

Version of Handler.postDelayed which adds the ability to specify token, enabling the use of Handler.removeCallbacksAndMessages.

inline fun Handler.postDelayed(delayInMillis: Long, token: Any? = null, crossinline action: () -> Unit): Runnable

Version of Handler.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

handler.postDelayed(200) {
    doSomething()
}

Return
the created Runnable

inline fun Handler.postDelayed(amount: Long, unit: TimeUnit, token: Any? = null, crossinline action: () -> Unit): Runnable

Version of Handler.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

handler.postDelayed(2, SECONDS) {
    doSomething()
}

Return
the created Runnable

inline fun Handler.postDelayed(duration: Duration, token: Any? = null, crossinline action: () -> Unit): Runnable

Version of Handler.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

handler.postDelayed(Duration.ofSeconds(2)) {
    doSomething()
}

Return
the created Runnable