> Hi,
> I'd like to create some sort of Thread which can be accessed by my
> main program..
> Specifically I'd like two classes, both with their own thread, one for
> parsing XML data and one for doing database operations, without
> actually interfering with the main UI-thread (slowdowns for
> example)...

Use AsyncTask for each of these.

> I was wondering if those should just extend Runnable, and maybe make
> them some sort of Singleton, or if these should be implemented as a
> Service ?

Use AsyncTask, perhaps mediated by a Service. I'd probably use a Service,
only because I like a stable foundation where I can get it, and activities
tend to be twitchy (e.g., user presses BACK, and they get destroyed). But,
since you're asking this in a very abstract fashion, I have no idea if a
Service is necessarily right for your case.

Another possibility, instead of AsyncTask, is to use an IntentService.
They both allow you to do work in the background without your own thread
management. I tend to use IntentService more for totally asynchronous
stuff (e.g., app widget updates, alarms with AlarmManager, etc.), where I
want the service to go away when there's no outstanding work to do.

> Or maybe they shouldnt be implemented at all as an
> individual Thread ?

Forking your own threads should only be taken after you have investigated
AsyncTask. AsyncTask doesn't handle every scenario where you might use
threads. However, since AsyncTask lets you do background work without your
own thread-management code, it is definitely worth looking into.

At the risk of sounding self-serving, you might want to look into getting
a book that covers threads and services in Android. The questions that you
are asking are rather involved -- I've barely scratched the surface of the
subject in this reply.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


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

Reply via email to