1

I am using this piece of code to stop gps locating the problem is that sometimes android kills my process starting it again... and the handle becomes invalid...making it impossible to stop the gps...how can i do this ?

here is the code:

lm.removeUpdates(locationListener);
locationListener = null;
opc0de
  • 11,557
  • 14
  • 94
  • 187

1 Answers1

2

Try-

locationManager.removeUpdates(locListener);

        if (locListener != null) {
            locListener = null;
        }
        if (locationManager != null) {
            locationManager = null;
        }

And make sure you initialize your handler in onResume() and not onCreate()

Also put the above piece of code in onLocationChanged() since, as you've got the location, you don't need gps (for quite some time at least) as you said.

Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • @opc0de : Did it work? Let me knw if it does or does nt. Or you may mark it as accepted alternatively. – Rajkiran Mar 17 '12 at 20:06