Leaving android app with back button
问题 I want the users of my android app to leave my app when they press back at a certain activity. Can this be done? 回答1: You can try something like this (shows a dialog to confirm exit): @Override public void onBackPressed() { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit") .setMessage("Are you sure you want to exit?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {