[英]Why does I'm not getting lifecycleScope in Java Android?
Exactly this below code I want to use in my existing Java class, because write now it is not possible to convert entire class in Kotlin : Exactly this below code I want to use in my existing Java class, because write now it is not possible to convert entire class in Kotlin :
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
viewModel.tasksEvent.collect { event ->
}
}
Kindly suggest the best approach.请建议最好的方法。 I know
AsyncTask
is deprecated.我知道
AsyncTask
已被弃用。
If I'm not mistaken Kotlin coroutines are not interoperable with Java .如果我没记错的话 Kotlin 协程不能与Java互操作。 To use Kotlin coroutines stick to the Kotlin code, don't try to use coroutines in Java .
要使用Kotlin 协程,请遵循 Kotlin 代码,不要尝试在Java中使用协程。 Try to convert Java file to Kotlin file using context menu item Convert Java File to Kotlin File .
尝试使用上下文菜单项将 Java 文件转换为Kotlin文件将Java文件转换为 Z539A32A5859D2409FFAZ174 文件Or move coroutines code to a separate Kotlin File.
或者将协程代码移动到单独的Kotlin文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.