user1479469
user1479469

Reputation: 45

Stopping GPS after Exit is pressed

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

Answers (3)

Alexis C.
Alexis C.

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

tolgap
tolgap

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

user1202136
user1202136

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

Related Questions