Android Development Basics: How to replace AsyncTask with Kotlin’s Coroutines

For a very long time in Android, if you needed to do anything asynchronously when making an app, you’d probably be using AsyncTask. AsyncTask is an API in Android’s framework that makes it easy(ish) to run operations in the background and return values when finished. And that makes sense. Unlike Kotlin’s Coroutines, AsyncTask has been around for a while, and it’s built right in.
However, both the design philosophy and implementation of AsyncTask have become somewhat outdated over the years. Because of that, Google has deprecated the AsyncTask API. You can still use it if you want, but Google doesn’t recommend doing so. Luckily, there are a whole bunch of alternatives to AsyncTask, including a feature of the Kotlin language — coroutines.
Kotlin’s coroutines API is an incredibly powerful framework which lets you do a whole bunch of things. This article is only going to scratch the surface of what’s possible. We’ll be going over the basics needed to migrate from AsyncTask to coroutines…

Written By: Zachary Wander

Original Article:

Leave a Comment