How to call a function after delay in Kotlin?

前端 未结 11 1951
南笙
南笙 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:45

    If you're using more recent Android APIs the Handler empty constructor has been deprecated and you should include a Looper. You can easily get one through Looper.getMainLooper().

        Handler(Looper.getMainLooper()).postDelayed({
            //Your code
        }, 2000) //millis
    

提交回复
热议问题