Asynctask vs Thread in android

Ram picture Ram · Aug 28, 2013 · Viewed 97.6k times · Source

In UI, to perform some background work, I used a separate Thread. But as suggested by others, I am now using AsyncTask.

What is the main difference between a Thread and an AsyncTask?

In which scenario, should I use a Thread or an AsyncTask?

Answer

Mohit picture Mohit · Aug 28, 2013

For long-running or CPU-intensive tasks, there are basically two ways to do this: Java threads, and Android's native AsyncTask.

Neither one is necessarily better than the other, but knowing when to use each call is essential to leveraging the system's performance to your benefit.

Use AsyncTask for:

  1. Simple network operations which do not require downloading a lot of data
  2. Disk-bound tasks that might take more than a few milliseconds

Use Java threads for:

  1. Network operations which involve moderate to large amounts of data (either uploading or downloading)
  2. High-CPU tasks which need to be run in the background
  3. Any task where you want to control the CPU usage relative to the GUI thread

And there are lot of good resources over internet which may help you:

http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html