Skip to main content
Android App Development3 min read

AsyncTask is Deprecated : What are the alternatives to it?

By Anjana Gausvami

AsyncTask is Deprecated : What are the alternatives to it?

What is AsyncTask ?

AsyncTask is an abstract class. It is an asynchronous task that runs on the background thread and executes results on the UI thread.

Currently, AsyncTask is deprecated in API level 30 because of its inconsistent behavior on different versions and swallows exceptions from the doInBackground method. It also causes Context leaks, missed callbacks or crashes on configuration changes.

AsyncTask is a helper class around Thread and Handler. It should be used for short operations. If you want to run threads for a long period of time you can use various APIs provided by java.util.concurrent like Executor, ThreadPoolExecutor & FutureTask.

Now what is an alternative for deprecated AsyncTask?

In the official document, it recommended Kotlin concurrency utilities and java.util.concurrent as an alternative.

In this article, We will use two methods. First is Using Executor and Handler & Second is Using Thread.  

1. Using Executor and Handler

Executor and Handler can be found in the java.util.concurrent package. The Executor performs background tasks while the Handler changes the user interface.

Here is an example of it.

Create instance of Executor

private val executor: Executor = Executors.newSingleThreadExecutor()

When the Executor executes a task and gives a result we will use Handler for UI changes. getMainLooper() method returns the main looper, which lives in the main thread.

private val handler = Handler(Looper.getMainLooper())

Execute method used to perform tasks asynchronously.

executor.execute {
// perform task asynchronously
handler.post {
// update the result to the UI thread
}
}

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import java.util.concurrent.Executor
import java.util.concurrent.Executors

class MainActivity : AppCompatActivity() {

   private val executor: Executor = Executors.newSingleThreadExecutor()
   private val handler = Handler(Looper.getMainLooper())

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)

       executor.execute {
           // perform task asynchronously
           handler.post {
               // update the result to the UI thread
           }
       }

   }
}

2. Using Thread

A thread refers to a single sequential flow of control within a program. It is one of the easiest alternatives. We can simply say that a thread is a way to execute a program.

Here is an example of how we can use the Thread:

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)

       Thread {
           // Do something in Background
           runOnUiThread {
               // Do something in UI
           }
       }.start()
   }
}

Now, Let’s review the runOnUiThread:

In some cases, the Main thread performs heavy operations. The user can add extra operations on the UI by loading the ANR and providing it. By using runOnUiThread, you will be able to perform the background operations on the worker thread while updating the result on the main thread.

Conclusion

As a result, we have learned an alternative to the deprecated AsyncTask.

Blogs

Field notes on shipping software, design, and everything in between.

AI SDK Laravel - library (1)
Web DevelopmentJul 3, 2026

Laravel AI SDK : A Complete Overview of Building AI Features in PHP

Laravel AI is Laravel’s official, first-party package for building AI features into PHP applications. Instead of pulling in…

Playwright MCP
Web DevelopmentJun 2, 2026

How I Audited and Fixed My Next.js Mobile UI in Minutes Using Playwright MCP

Every developer knows the tedious dance of mobile UI auditing. You deploy your site, open Chrome DevTools, toggle…

agile team management thumbnail
StoriesJul 19, 2023

Agile Team Management Unleashed: Insights from Top 5 Management Books for Small IT Agencies

Welcome to our blog, where we embark on a journey to unlock the secrets of maintaining a small…

Ways to create Effective UI/UX Design Portfolio
UI/UXDec 15, 2022

Ways to create Effective UI/UX Design Portfolio

In an industry where education and experience are not necessarily requirements for a dream position, a UX design…

5 Prototyping Tools for UI/UX Designers
UI/UXSep 12, 2022

5 Prototyping Tools for UI/UX Designers

It may sound cliche, but it’s also true that prototyping plays an important role in communicating how the…

Dark UI Design : Best Practices
UI/UXAug 25, 2022

Dark UI Design : Best Practices

Dark theme was introduced with IOS 13 in September 2019 followed by Android 10(Q) in May 2020 after…

What is viewBinding in Android and How we can use it?
Android App DevelopmentAug 24, 2022

What is viewBinding in Android and How we can use it?

Till now when we want to connect an XML element to a java or kotlin file we always…

5 Figma Plugins that can be used to create Good User Interface
UI/UXAug 24, 2022

5 Figma Plugins that can be used to create Good User Interface

After the launch in 2016, Figma has grown to become one of the leading UI design tools on…

MySQL Tips & Tricks : Functions
Web DevelopmentAug 24, 2022

MySQL Tips & Tricks : Functions

In our previous article on MySQL, we covered Triggers. In this article we are covering another important feature…

Free consultation to scope your
creative projects

Book demo

FAQ

Ask AI to summarize QuriousClick
Have a project in mind?Tell us what you're planning and we'll help you shape the scope, timeline and next steps.
Book a discovery call
  • QuriousClick is a design and development studio. Since 2014 our in-house team has designed, built and supported websites, web and mobile apps, brands and AI products for 100+ customers worldwide.