I implemented the GPS in my app, in one Activity like this:
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location location)
{
if (location != null) { //do something}
...
}
This is working fine. After evolving the app more I realized that I need to use the GPS in more than one activity. I need to be able to check if gps is active and what location does it return from 3 activities.
Imagine this scenario: the user starts the app. In background the GPS is trying to get satellite connection while the user selects some options. When I get to an activity that requires Location info I ask for it.
How can I achieve this ? Should this be running in another thread ? Please advise me. Thank you