Stop pressing the GPS button on the rear panel

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); } 
+4
source share
1 answer

Just call removeUpdates() in onPause() or onStop() , possibly the last one.

+4
source

Source: https://habr.com/ru/post/1304372/


All Articles