What exactly is the purpose of an Async task as it is written?

0 Dol Lod · August 22, 2015
The ASYNC Task looked incredibly hard to use. I pretty much created my own version using a thread in the background that occasionally called on the mainuithread for anything it needed. 

So can someone please explain the advantages of using an actual AsyncTask as opposed to simple creating a thread and start it with a runnable. 

Main advantages for custom thread that I can see, If I am wrong, please correct me. I don't know much about ASYNCTasks.

1) More API flexibility. No more onPostExecute defined for API levels 9 or higher. You could easily write it yourself with no API restrictions.
2) Simpler parameters. No more params.
3) Uses a simple thread interface with a runnable.
4) Very easy to understand. No looking up documentation or googling about how to use an async task.

Post a Reply

Replies

Oldest  Newest  Rating
0 Durant ShaoQiang · August 23, 2015
 when we start a new thread , we usually do the time-consumed tasks like  internet access , IO , downloading etc, ,and if we do these in the main thread which is also known as the ui thread will cause ANR exception ,  whats more ,usually we need to know when the task is finished so we can do some relevant operation such as show the image downloaded from the server,
 the Asynctask has  designed those callbacks we need already .
0 Dol Lod · August 24, 2015
Thank you for the explanation, but I still don't understand the use of the AsyncTask class (provided by Android).

That is what I don't understand. I found it was hard to use and API level relevant. 

Designing your own thread to replicate the AsyncTask seems much more productive.
  • 1

Java / Android Development

107,214 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator