How to show a dialog to confirm that the user wishes to exit an Android Activity?
问题 I\'ve been trying to show a \"Do you want to exit?\" type of dialog when the user attempts to exit an Activity. However I can\'t find the appropriate API hooks. Activity.onUserLeaveHint() initially looked promising, but I can\'t find a way to stop the Activity from finishing. 回答1: In Android 2.0+ this would look like: @Override public void onBackPressed() { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Closing Activity") .setMessage("Are you sure you