Google Deprecating Android AsyncTask

If you are writing multi-threaded asynchronous code using Android Studio you can’t help but have noticed that any reference to AsyncTask appears with a strikethrough. This, as we all know, is the dreaded sign that a feature of the Android SDK on which we have relied for years (in the case of AsyncTask it has been a decade) has been deprecated.

It is uncertain how long before the AsyncTask class is removed from a future Android release. All we know is that eventually it will be gone.

From what we have learned the removal of AsyncTask is the result of a tendency for memory leaks to occur when implementing multi-threading using this class.

For Kotlin programmers, the recommended course of action is to switch to using Coroutines. For those still programming in Java, the only option is to directly work with threads, or to use the Java concurrent utilities (java.util.concurrent). For more details read A Basic Overview of Java Threads, Handlers and Executors.


Categories