Real difference between AsyncTask and Thread

Fran b picture Fran b · Aug 1, 2012 · Viewed 24.4k times · Source

I have been reading Android documentation (AsyncTask, Thread) and vogella tutorial about this matter, but I have doubts yet.

For example, I want to send a message from an Android app to a server. And I would like this process to be responsive. What should I use?

I have seen examples where they create a new Thread for not block UI, but this way we don't have the progress of process, also you have to process the response within the Thread because the run() method doesn't returning anything.

AsyncTask seems better option than Thread, but I don't know what are the consequences of using an AsyncTask instead of a Thread.

Answer

Dwivedi Ji picture Dwivedi Ji · Oct 5, 2013

Please read this blog

http://crazyaboutandroid.blogspot.in/2011/12/difference-between-android.html

and Details are:

Difference between Android Service,Thread,IntentService and AsyncTask

When to use ?

Service

   Task with no UI, but shouldn't be too long. Use threads within service for long tasks.

Thread

- Long task in general.

- For tasks in parallel use Multiple threads (traditional mechanisms)

AsyncTask

- Small task having to communicate with main thread.

- For tasks in parallel use multiple instances OR Executor