【发布时间】:2019-07-19 03:48:24
【问题描述】:
我在一个返回值的函数中有一个后台任务。我使用 Kotlin 协程。
我可以这样做:
fun backTask(): Int {
// Might take a few seconds
return 10
}
GlobalScope.launch(Dispatcher.Main){
val num = withContext(Dispatcher.IO) { backTask() }
toast("Number: $num")
}
所以它起作用了。究竟是什么让我定义了我的后台任务功能,suspend function
【问题讨论】:
标签: android kotlin kotlin-coroutines coroutine background-task