Received: by 10.66.81.129 with SMTP id a1mr1272712pay.30.1352908624407; Wed, 14 Nov 2012 07:57:04 -0800 (PST) X-BeenThere: android-developers@googlegroups.com Received: by 10.68.232.200 with SMTP id tq8ls2614616pbc.8.gmail; Wed, 14 Nov 2012 07:51:37 -0800 (PST) Received: by 10.68.141.45 with SMTP id rl13mr7100992pbb.8.1352908297894; Wed, 14 Nov 2012 07:51:37 -0800 (PST) Date: Wed, 14 Nov 2012 07:51:37 -0800 (PST) From: Streets Of Boston To: android-developers@googlegroups.com Message-Id: <73e7d0a6-24b7-416d-a58b-32f9e277cd96@googlegroups.com> In-Reply-To: References: Subject: Re: AsyncTask design question MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_283_13734406.1352908297267" ------=_Part_283_13734406.1352908297267 Content-Type: multipart/alternative; boundary="----=_Part_284_13238465.1352908297267" ------=_Part_284_13238465.1352908297267 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Create a separate AsyncTask subclass for each different task that needs to be done. It is bad Java design to create one large AsyncTask subclass that handles everything in your app. That would mean you'd have to create a large 'doInBackground' method (being able to handle all cases), possibly create a large 'onPostExecute' as well, etc, and riddle your code with 'if' statements or large 'switch' statements. In the end, all your AsyncTask instances/objects, regardless which subclass they actually are, are run on one 'global' system queue and 'global' pool of threads. They all share it. For executing a particular AsyncTask instance/object: You can execute an AsyncTask instance/object only once (i.e. call 'execute' on the object only once). --- Anton. On Tuesday, November 13, 2012 4:44:16 AM UTC-5, 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 > ------=_Part_284_13238465.1352908297267 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Create a separate AsyncTask subclass for each different task that needs to = be done. 

It is bad Java design to create one large Async= Task subclass that handles everything in your app. That would mean you'd ha= ve to create a large 'doInBackground' method (being able to handle all case= s), possibly create a large 'onPostExecute' as well, etc, and riddle your c= ode with 'if' statements or large 'switch' statements.

In the end, a= ll your AsyncTask instances/objects, regardless which subclass they actuall= y are, are run on one 'global' system queue and 'global' pool of threads. T= hey all share it. 

For executing a particular= AsyncTask instance/object: You can execute an AsyncTask instance/object on= ly once (i.e. call 'execute' on the object only once). 

=
--- Anton.

On Tuesday, November 13, 2012 4:44:16 AM UTC-5= , 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 b= etter 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 an= d making seperate AsyncTasks for every screen of my application will be goo= d for performance.

Thanks for any advice.
Albertus
------=_Part_284_13238465.1352908297267-- ------=_Part_283_13734406.1352908297267--