Paul
Paul

Reputation: 2515

How to stop GPS on Android app when not in use

I have created an app that displays the user location on google maps using LocationListener and GPS. I'm trying to turn GPS off when the user navigates away from the app, but everything I try doesn't work, I can still see the GPS icon active at the top of the screen. At present I have:

@Override
protected void onPause() {
    super.onPause();
    // Turning off
    locationManager.removeUpdates(locationListener);
    locationManager = null;

}

help please :(

Upvotes: 1

Views: 2201

Answers (2)

Paul
Paul

Reputation: 2515

Sorted it!

It turned out the problem was in my onResume with these two lines:

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();

I never bothered looking at them because I didn't expect the onResume state to be affecting the onPause.

Thanks for your help Javanator.

Hope this helps someone else :)

Upvotes: 0

Rohit Sharma
Rohit Sharma

Reputation: 13825

Try Your test over Device. If using device uninstall your application and restart your device and install again.

make sure the listener you are removing is the same for which you requested updates. it should work then.

Upvotes: 2

Related Questions