I don’t need a strict code related answer I just need somebody to tell me what I am missing.
My application has to retrieve from a web service (xmlrpc) the positions of some users I know and update their position on a MapView.
So I decided to use a Service and an Activity extending MapActivity to show results.
I thought about two solutions:
I ) start the service and make it ask every minute for these positions and send them to the activity as a bundle via intent. (This didn’t work out well, since once shown I couldn’t find a method to let the activity continue refresh itself until she stop receiving intents+data from the service)
II ) Incorporate a thread within the activity which starts the service via context.startService(…) every minute. And the MapUI refresh itself once the service send back an intent and stop itself. (Maybe I will fall in the same problem category as before I haven’t tryied yet).
I am also giving directions (via maps.google ws) in this way I’d like to refresh only users positions on the map and save the route.
What Am I missing do you have any suggestions? related to activities/services internal mechanics, don’t know launch modes, use broadcast receivers or intent filters?
Thanks in advance
you may use AlarmManager with setRepeating(), that way you can send an Intent periodically to start/update your service. You should really separate fetching data (service) and updating the Activiy UI (from a DB?).
Otherwise you may have to bind your activity to the service, and communicate via an interface.
My 2 cents