Android Delay Execution (Kotlin)

April 14, 2019
using Timer.schedule
import java.util.Timer
import kotlin.concurrent.schedule

// 1000 = 1s
val timeout = 1000

Timer().schedule(timeout) {
    // do something on background thread

    launch(Dispatchers.Main) {
        // do something on main/ui thread
    }
}

NOTE: The schedule callback is on a background thread.

NOTE: Refer to Kotlin Coroutine to launch Main/UI thread

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.