How to call a function after delay in Kotlin?

前端 未结 11 1935
南笙
南笙 2020-11-30 19:07

As the title, is there any way to call a function after delay (1 second for example) in Kotlin?

11条回答
  •  暖寄归人
    2020-11-30 19:49

    You have to import the following two libraries:

    import java.util.*
    import kotlin.concurrent.schedule
    

    and after that use it in this way:

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

提交回复
热议问题