Does anyone know how to easily arrange multiple calls to an AsyncTask execution in a queue or something and then execute them in a serial fashion?
I want the called async task to wait while the one before it is finished, but is seems I can’t accomplish this, even if I test the status of the one currently being executed.
Any ideas how to solve this? I’ve seen that in the honeycomb API there is a method executeOnExecutor() with a SERIAL_EXECUTOR, I guess it implements what I’ve described. However, I’m not developing for honeycomb.
Thanks!
You might try IntentService. From the reference:
I ran the service from a broadcast receiver as follows:
It worked as advertised. The requests are serialized fine. The service started when a request was received. The service stopped after the last request processed. The requests were processed FIFO.
I created the intentservice using right click on the source package name and selecting New/Class. I used intentservice as the superclass. The constructor has an arguement of ‘name’. I changed it to:
All of the code for the service went into the onHandleIntent function. I didn’t have to use any other @Override functions.
Hope this is what you wanted…
Notes: The variable ‘context’ is a passed parameter in onReceive. I changed the names in the code from XxxxService to ‘Service’ or ‘service’. Finally, I create a class in all my projects called GC. It is a container class for global constants. GC.EXTRA_SERVICE_DATA is a global String defining the extra key.