My application uses GPS updates while it is running, and I would like it to stop when the user returns from the application, as I assume that he will continue to spend a lot of energy on the battery. I tried to intercept the click of the back button, but it does not seem to work. I am not sure if this is because it is not executing code, or I am using the wrong command. Any help would be greatly 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); }
source share