I have a service which can be called from Activities in an app.
The service contains of two different AsyncTasks that downloads data and populates a DB. The tasks downloads different data, and the operations may take some time.
So I want to prevent the Tasks from being run simultaneously, but if one task is running I would like to queue the second task.
This could happen if the users switch activity before the task is completed.
How can this be done? Can I sleep the second task in some way?
Hope this is understandable 🙂
Thanks guys!
Would an IntentService be more appropriate? You can fire tasks at it, and it’ll execute them one at a time in a single background thread.
If you need to get results back from these operations, you can use a
BroadcastReceiverto capture messages from the service.