What function do you call when you press the back button on Android. My requirement is that when the application starts and the user clicks the "Back" button, the application status should be saved in the database, and the user should be able to see the status when he returns to the application.
Browsing over the Internet, I realized that we can process the control using the onKeyDown() function. However, even if I use it in my code, the function is not called when I click the back button. Below is the function:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(null,"In on Key Down"); if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); return true; } return super.onKeyDown(keyCode, event); }
Please suggest if someone comes across the same / similar scenario.
source share