Which is the good place to ask user, whether (s)he wants to exit the app when (s)he clicked the back button? I considered the onPause and onStop, but these methods fires whenever app is gone behind the other apps.
Update:
The app should also ask if user is trying to exit the app from a button (in app itself), not the Back hard key.
You can do it in the following way;
Since, you want to prompt user when (s)he clicked the back hard button, as suggested by others, you can override the
onBackPressed()method and call the above method from there;As suggested by @Martyn, you can use the
onKeyDownto achieve the same;For this, call the
doExit()from your button’s onClick;Related Info: