Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
AsyncTask design question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Albertus Kruger  
View profile  
 More options Nov 13 2012, 4:44 am
From: Albertus Kruger <albertus.kru...@gmail.com>
Date: Tue, 13 Nov 2012 01:44:16 -0800 (PST)
Local: Tues, Nov 13 2012 4:44 am
Subject: AsyncTask design question

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TreKing  
View profile  
 More options Nov 14 2012, 5:16 am
From: TreKing <treking...@gmail.com>
Date: Wed, 14 Nov 2012 04:11:43 -0600
Local: Wed, Nov 14 2012 5:11 am
Subject: Re: [android-developers] AsyncTask design question

On Tue, Nov 13, 2012 at 3:44 AM, Albertus Kruger
<albertus.kru...@gmail.com>wrote:

> 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 ?

One class that handles everything seems like a terrible idea. An AsyncTask
should represent a single task. It does one thing, reports progress on it,
and returns a result. That's it.

--------------------------------------------------------------------------- ----------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mukesh Srivastav  
View profile  
 More options Nov 14 2012, 5:57 am
From: Mukesh Srivastav <mukicha...@gmail.com>
Date: Wed, 14 Nov 2012 16:22:26 +0530
Local: Wed, Nov 14 2012 5:52 am
Subject: Re: [android-developers] AsyncTask design question

Hi All,

Have a separate Async task class which serves the HTTP Request to all of
your Activities and let your Activities implments a listener which helps
the AsycnTask class to get the data from "onpostexecutes" method.

here is an example which i have written in a blog.

http://www.androidsnippets.com/asyntask-in-android

Mukesh

--
Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Nov 14 2012, 10:51 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Wed, 14 Nov 2012 07:51:37 -0800 (PST)
Local: Wed, Nov 14 2012 10:51 am
Subject: Re: AsyncTask design question

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Indicator Veritatis  
View profile  
 More options Nov 15 2012, 3:40 am
From: Indicator Veritatis <mej1...@yahoo.com>
Date: Thu, 15 Nov 2012 00:40:24 -0800 (PST)
Local: Thurs, Nov 15 2012 3:40 am
Subject: Re: AsyncTask design question

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-developer...
for several different ways of dealing with this complication, choose the
one best for your own application.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »