在Kotlin中延迟后如何调用函数? [英] How to call a function after delay in Kotlin?

查看:59
本文介绍了在Kotlin中延迟后如何调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,在Kotlin中延迟(例如1秒)后有什么方法可以调用吗?

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

推荐答案

您可以使用示例(感谢@Nguyen Minh Binh-在此处找到它: http://jamie.mccrindle.org/2013/02/exploring-kotlin-standard-library-part-3.html )

example (thanks @Nguyen Minh Binh - found it here: http://jamie.mccrindle.org/2013/02/exploring-kotlin-standard-library-part-3.html)

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

Timer("SettingUp", false).schedule(500) { 
   doSomething()
}

这篇关于在Kotlin中延迟后如何调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆