views:

52

answers:

1

Hi, I'm trying to find some simple way of queueing tasks on a thread that is NOT the UI-thread.

I have a BroadcastReceiver that responds to Intents each time an image is taken, and notifies my Service each time that happens. The Service will have to do some processing (scaling and rotating an image) and I would like to do this on a new thread (The service is running on the same thread as my main Activity). So I've been looking at AsyncTask for that.

My problem is that if the next image is taken BEFORE the previous has been fully processed, I will have two AsyncTasks running simultaneously, and I don't want that. I would like to queue the processing of the next one until the first one is done.

So basically I want two threads. One is the standard UI-thread, and another one that is my worker thread where i can have a queue of task to perform.

What would be the best approach?

+1  A: 

I have a BroadcastReceiver that responds to Intents each time an image is taken, and notifies my Service each time that happens. The Service will have to do some processing (scaling and rotating an image) and I would like to do this on a new thread (The service is running on the same thread as my main Activity). So I've been looking at AsyncTask for that.

IntentService is a fine solution for this sort of problem, as it combines a work queue with a background thread in a Service. You just override onHandleIntent() to do your actual work.

My problem is that if the next image is taken BEFORE the previous has been fully processed, I will have two AsyncTasks running simultaneously, and I don't want that. I would like to queue the processing of the next one until the first one is done.

IntentService will only process one Intent at a time.

CommonsWare
Thank you for the quick reply, will try it out tomorrow!
Joel