More activities need to get informations about location, so I don’t think would be a good idea making each of them a location listener.
For this reason my idea would be letting a background service listen for changes, then when an activity wants to know current latitude/longitude it just asks them to service.
Problem is that, when current activity goes on pause (screen fades, user presses home button,ecc.), service should stop listening (in order to avoid battery waste).
Can you suggest me a good pattern to achieve what I’m trying to do?And is it, according to you, the right way to proceed?
You should create a bound service – this service is stopped, once all bound activities are deleted (not onPause…).
For onPause detection you need to overwrite the application class and create a static value “inForeGround”.
Here are some infos for a bound service!