Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Service Multiple Thread Design

A new question about android and services. Currently I'm developing a App that should send images to a server. It should also be possible to send more images parallel.

I made a service that creates for every image a new image. The activity can bind to that service and gather information about the progress. I want to show the current status for every image in a notification (and when the user clicks a notification, an activity with the progress for that image should be shown).

But I get several problems with that approach. There are errors with binding, the notification pending event starts the activity completly new, so I lose information about currently sending images and so on.

Can someone plase tell me, how I could design such a problem in a appropriate way.

thx

like image 829
Masala Avatar asked May 28 '10 09:05

Masala


1 Answers

I would use a Controller object that is created in your application class. This controller is the same for all your activities. If an image upload is started the controller creates a new service/thread and monitors it state and shows the notification. Every activity now can ask the controller for the state of its process and show the corresponded information to the user. This way the controller living in the application lifecyle will bind to the service and not the short lived activity

There was a talk from mark brady on droidcon about this you can find the slides on slideshare. It gets interesting in the later part of the slides when the architecture mark used is explained. I fought with the same problem for some weeks and came to the same results and I'm glad that finally some kind of resource exists on the net on this topic.

like image 119
Janusz Avatar answered Sep 27 '22 20:09

Janusz