I see several people have already replied, and correctly explained that having just one AsyncTask is a bad idea. But none seem to have commented: the very question, posed as a choice between one AsyncTask vs. one for each screen, seems to imply a fundamental misunderstanding of the purpose of AyncTask.
The purpose of AyncTask is not to handle something for every screen. It is to handle long tasks that do not belong in the UI thread in the first place, the prototypical example being the upload or download of a single file via HTTP, with occasional, light communication back to the UI thread, e.g. progress updates on that up/download. AsyncTask is not a general purpose multi-tasking tool. As has already been pointed out, you can call the executor only once, and then not again. So it is not good for a background task that sits and waits for messages, processing each in turn. Looper/Handler is more suitable for that. AsyncTask is more useful for "one shot" tasks, and specifically for those that take too long to allow in the UI thread. Even for these tasks, complications emerge when you use AsyncTask and the phone is rotated. See https://groups.google.com/forum/?fromgroups=#!topic/android-developers/4dW4-KMUKJI for several different ways of dealing with this complication, choose the one best for your own application. On Tuesday, November 13, 2012 1:44:16 AM UTC-8, Albertus Kruger wrote: > > Hi, > > I am new to Android programming. I would like to know if it is better to > have seperate AsyncTasks for every screen on your application or is it > better to have one AsynTask class that handles all processing from > different screens on my application ? > > I have looked at stackoverflow but its still not clear to me. I'm thinking > one class might be a lot of overhead and making seperate AsyncTasks for > every screen of my application will be good for performance. > > Thanks for any advice. > Albertus > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en