How to call a function after delay in Kotlin?

前端 未结 11 1953
南笙
南笙 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条回答
  •  猫巷女王i
    2020-11-30 19:51

    If you are in a fragment with viewModel scope you can use Kotlin coroutines:

        myViewModel.viewModelScope.launch {
            delay(2000)
            // DoSomething()
        }
    

提交回复
热议问题