Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Pavlos Isaris
10,863 PointsDifference between Async task and Thread
Hello!
Does anybody know what are the differences between an AsyncTask (like the one used in the Blog Reader project) and a Java Thread?
Is there also a special reason why we used the AsyncTask instead of the Thread class? This question I think is directed to our instructor, Ben Jakuben.
Thanks in advance!
1 Answer
Ernest Grzybowski
Treehouse Project ReviewerAsyncTasks were added as a convenience in android. If you look at the documentation for it, you will see that it provides you with four things to help you with you background operations.
http://developer.android.com/reference/android/os/AsyncTask.html
- onPreExecute()
- doInBackground(Params...)
- onStatusUpdate(Progress...)
- onPostExecute(Result)
You are not required to use all of them, but you have to realize that you cannot update your GUI from doInBackground, which is where onPostExecute usually comes in.
I highly recomend reading the AsyncTask documentation from the link above. After you are done with that, take a look at some of these answers as well.
http://stackoverflow.com/questions/17954383/service-or-thread-or-asynctask
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherGreat answer, Ernest! From that documentation, here are the relevant points about why we use AsyncTask instead of a regular Thread: