File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes A question about multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "A question about multithreading" Watch "A question about multithreading" New topic

A question about multithreading

Rodrigo Bossini
Ranch Hand

Joined: Jul 03, 2009
Posts: 113

I have attended a lecture by Tim Bray a while ago in Google Developer Day and he talked a little about multithreading development in Android. However the time was so short he barely could talk about it. So, I was under the impression that multithreading developing in Android has something similar to the SwingWorker class from Java 6. Can you guys elaborate a little about this?

I see wind mills
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Android has the very handy AsyncTask and Loopers and Handlers. AsyncTask should be your stop for background processing.
Monu Tripathi

Joined: Oct 12, 2008
Posts: 1369

Also, note that AsyncTask was written to provide a convenient, easy-to-use way to achieve background processing in Android apps, without worrying too much about the low-level details(threads, message loops etc). It provides callback methods that help to schedule tasks and also to easily update the UI whenever required.

However, it is important to note that when using AsyncTask, a developer is submitting to its limitations, which resulted because of the design decisions that the author of the class took. For e.g.
1. You should instantiate AsyncTask only on UI thread
2. there is a limit to the number of jobs that can be scheduled using AsyncTasks.

Handler is more transparent of the two and probably gives you more freedom; so if you want more control on things you would choose Handler otherwise AsyncTask will work just fine.

[List of FAQs] | [Android FAQ] | [Samuh Varta]
I agree. Here's the link:
subject: A question about multithreading
It's not a secret anymore!