AsyncTask deprecated in Android 11: what alternatives to use?
Hello everyone! I'm a beginner in Android development with Kotlin, and I've run into a problem. I spent a long time learning to use AsyncTask for background tasks, such as loading data from the network or working with a database. But recently I discovered that in Android 11, the AsyncTask API is marked as deprecated. Now I don't understand how to properly organize asynchronous code in my projects.
Here's an example of my old Kotlin code that I used to load a list of users:
```kotlin
class LoadUsersTask(private val callback: (List) -> Unit) : AsyncTask>() {
override fun doInBackground(vararg params: Void?): List {
// Here I make a network request
return fetchUsersFromApi()
}
override fun onPostExecute(result:
No answers yet.
Log in to leave an answer