I have an application currently that uploads images to a server. To upload these images, I use an AsyncTask which works allright. It uploads the image, shows notifications for it along with the progress. For multiple images, separate async tasks are created. But I need something more:
I think a background Service is what I need. My question is can I use a Service to accomplish these tasks:
The main roadblock for me is detecting if the service is running. Also, is it possible to let the Service know I have added another file to the queue (adding file to the queue is just an SQL insert into the table. The service should append the new file to the queue once the activity says a file has been added)
Edit:
Here is a pseudocode of what Im trying to achieve:
Service service = new Service();
If service.isRunning{
service.itemAddedToQueueAndUpdateNotification()
}else{
service.start()
}
And some callback like
onServiceUpdateRecieved(){
//Update UI
}
You may use an Intent in order to broadcast either the new schedule (sent by activity, received by service) or the actual upload result (sent by service, received by activity, if active)