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.
If I'm not mistaken Kotlin coroutines are not interoperable with Java . To use Kotlin coroutines stick to the Kotlin code, don't try to use coroutines in Java . Try to convert Java file to Kotlin file using context menu item Convert Java File to Kotlin File .Or move coroutines code to a separate Kotlin File.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.