简体   繁体   English

Kotlin Coroutines 是否替换 AsyncTask?

[英]Does Kotlin Coroutines replace AsyncTask?

Is AsyncTask still needed?还需要AsyncTask吗?

In Android with Java, we used to implement an AsyncTask and AsyncTaskLoader , but recently I've been beginning to learn Kotlin and I've noticed that things like that are done by Kotlin Coroutines. In Android with Java, we used to implement an AsyncTask and AsyncTaskLoader , but recently I've been beginning to learn Kotlin and I've noticed that things like that are done by Kotlin Coroutines.

AsyncTask it's officially deprecated since Android11 AsyncTaskAndroid11起已正式弃用

https://developer.android.com/reference/android/os/AsyncTaskhttps://developer.android.com/reference/android/os/AsyncTask

Coroutines are the recommended choice, and considering Kotlin is the official language since 2017, then using AsyncTask is no longer a standard option.协程是推荐的选择,考虑到Coroutines是自 2017 年以来的官方语言,因此使用AsyncTask不再是标准选项。

Yes, you use Kotlin Coroutines to perform async operations now.是的,您现在使用 Kotlin 协程来执行异步操作。

If you are looking for Coroutine usage, then here is an example of using Coroutines to fetch data from different sources asynchronously:-如果您正在寻找 Coroutine 的用法,那么这里有一个使用 Coroutines 从不同来源异步获取数据的示例:-

https://codingnconcepts.com/kotlin/fetch-data-from-sources-async/ https://codingnconcepts.com/kotlin/fetch-data-from-sources-async/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用 Kotlin 协程替换 JobService()? - Replace JobService() by Kotlin Coroutines? 使用Kotlin协同程序替换LocalBroadcastManager for Firebase消息传递 - Using Kotlin Coroutines to replace LocalBroadcastManager for Firebase messaging 使用 Kotlin 协程替换 BLE 回调 - Replace BLE callbacks using Kotlin Coroutines 如何用 Kotlin 的协程替换回调 - How replace callback by Kotlin's coroutines 如何简单地用RX /协程替换android AsyncTask并返回一个值? - How to simply replace android AsyncTask with RX / Coroutines and return a value? Kotlin 中的协程是否像线程一样工作? - does coroutines in Kotlin work like threads? Kotlin 中的 suspend 关键字可以在没有协程的情况下做任何事情吗? - Does the suspend keyword in Kotlin do anything without coroutines? 使用 runBlocking 的 Kotlin 协程单元测试不等待执行 - Kotlin coroutines unit testing with runBlocking does not wait for execution Xamarin 是否支持 Xamarin Android 绑定库中的 Kotlin 协程? - Does Xamarin support Kotlin coroutines in a Xamarin Android Binding Library? Kotlin 协程如何管理在主线程上调度所有协程而不阻塞它? - How does Kotlin coroutines manage to schedule all coroutines on the main thread without block it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM