开发者

Stopping GPS on back button press

My applic开发者_如何学Pythonation uses GPS updates while it is running and I would like that to stop when the user back out of the app as I assume it will continue wasting a lot of battery power. I've tried intercepting the back button press but it doesn't seem to work. I'm not sure if this is because it's not executing the code or I'm using the wrong command. Any help would be appreciated.

public boolean OnKeyDown(int keyCode, KeyEvent event){
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
    lm.removeUpdates(this);
        return true;    
    }
    return super.onKeyDown(keyCode, event);
}


Just call removeUpdates() in onPause() or onStop(), probably the latter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜