Reputation: 45
I have an application which tracks the location with the help of GPS. Now when I enter back the Tracking is still going on. This continues even when I press the exit button. I have used finish() , but GPS doesn't stop when I press exit button.
Upvotes: 0
Views: 230
Reputation: 93842
To interrupt GPS :
myLocationManager.removeUpdates(myLocationListener);
Doing nothing on the key back pressed event:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
myActivity.finish();
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
myLocationManager.removeUpdates(myLocationListener);
myActivity.finish();
}
return super.onKeyDown(keyCode, event);;
}
Upvotes: 1
Reputation: 9778
Seeing as you have a MyLocationOverlay
in your code, this start a SensorThread
on its own. You will have to disable that too.
protected void onPause() {
//....your code
myLocationOverlay.disableMyLocation();
}
and it will shut that down too.
Upvotes: 0
Reputation: 11547
Your activity needs to implement the onPause
method, which is triggered when the user leaves it. Inside it, you can stop the GPS by calling:
myLocationManager.removeUpdates(myLocationListener);
Upvotes: 0