简体   繁体   English

为什么我在 Java Android 中没有得到生命周期范围?

[英]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.

相关问题 为什么我在Android平台(已经在Java中工作)上得到FileNotFoundExceptoin? - Why I'm getting FileNotFoundExceptoin on Android platform (that already worked in Java)? 为什么我会收到“服务未注册”异常,即使我没有在 Android - Java/Kotlin 中使用任何服务? - Why does I'm getting "Service not registered" exception, even though I not used any service in Android - Java/Kotlin? 为什么我得到不同的Java版本 - Why I'm getting different java versions 为什么我在 android 监视器中收到此错误? - why i'm getting this error in android monitor? 为什么我收到java.security.InvalidKey异常? - Why I'm getting java.security.InvalidKey Exception? 为什么我在 Java 中遇到堆空间错误? - why i'm getting heap space error in java? 不知道为什么我收到java.util.NoSuchElementException错误 - Not sure why i'm getting an java.util.NoSuchElementException error 有人可以解释为什么我在Java中遇到此错误吗? - Can someone explain why I'm getting this error in Java? 为什么我收到错误?com.android.volley.timeouterror - Why i'm getting error?com.android.volley.timeouterror 为什么在尝试使用 android studio java web 服务器连接到我的 PC 上的服务器时出现错误? - Why when trying to connect using android studio java web server to my server on the pc i'm getting error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM