Guys, you need to organize the exit from the application not with MainActivity, but with activity running, second, third, etc. When using the code below, the output is carried out in the previous activity .. I use the following code:
@Override public void onBackPressed() { new AlertDialog.Builder(this) .setTitle("Внимание!") .setMessage("Вы действительно хотите выйти?") .setNegativeButton(android.R.string.no, null) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Activity2.super.onBackPressed(); } }).create().show(); }
Activity.finishAffinity()- it closes all activities, but only withAPI16- woesss