Kotlin Call Function After Deplay

April 9, 2019

Timer Schedule

import java.util.Timer
import kotlin.concurrent.schedule

Timer().schedule(5000) {
    // do something
}

Kotlin Coroutines Delay

// launch in background thread
launch(Dispatchers.Default) {
    delay(5000L)
    // do something
}
// launch in main/ui thread
launch(Dispatchers.Main) {
    delay(5000L)
    // do something
}

NOTE: Refer Kotlin Coroutines Delay Job or Setup Android Kotlin Coroutines (1.1) With Coroutine Scope.

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