Thanks for your help on this.

I managed to stick with the original AsyncTask and push more operations off
to a different thread so the UI is far more responsive.

Thanks again
Don


On Fri, May 29, 2009 at 12:58 AM, Yousuf <[email protected]> wrote:

>
> Here is an approach that we took since AsyncTask didn't totally
> satisfy our needs.
>
> We added our own AbstractAsyncTask that extended AsyncTask and added a
> field to it of our own type called CallbackHandler<Result>.
> CallbackHandler is an interface that has 2 methods,
>
> onSuccess(Result result)
> onFailure(Exception e)
>
> Any activity that starts a task that extends AbstractAsyncTask needs
> to pass in a callbackhandler to it.
>
> Our activites usually implement Callbackhandler and our asynctasks are
> no longer inner classes. In the onPostExecute our AbstractAsyncTask we
> call the onSuccess or onFailure methods on the callbackHandler
> instance depending on whether the task was successfull or not.
>
> I think this was a much better way since we avoided inner classes and
> made our code much more readable.
>
> Yousuf
>
>
> On May 26, 3:58 pm, Don Oleary <[email protected]> wrote:
> > Hi guys
> >
> > I have a question around threading. I have one Activity that does the
> > following tasks
> > on first load
> >
> > - Queries the DB
> > - Aggregates the results (some intensive post processing)
> > - Displays the results to the user
> >
> > Depending on the amount of data, this can take a bit of time. I am trying
> to
> > push this
> > DB query and post processing off to a separate thread to the UI so the
> user
> > will perceive the app to be faster while also avoiding the "application
> not
> > responding"
> > message.
> > I can successfully do this using an inner class that extends AsyncTask,
> and
> > can update Views (set as member variables of the Activity class) that
> have
> > been defined in XML with the updated content. Where I am running into
> > problems is when I need to dynamically create views (TableRows for
> example).
> > Can I (should I) access the App Context object from the extended
> AsyncTask
> > inner class ?
> >
> > Where one is dynamically creating views, what is the best way to do this
> in
> > a separate thread to the UI ?
> >
> > Regards
> > Don
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to