[英]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
AsyncTask
自Android11
起已正式弃用
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.