1) Добавим кнопку в res/layout/main.xml
2) Добавим код в Main.java
2) Добавим код в Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button but1 = (Button) findViewById(R.id.button1); but1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog.Builder bui1 = new AlertDialog.Builder(Main.this); bui1.setMessage("Do you want to quit?"); bui1.setCancelable(false); // запрет возвращаться bui1.setPositiveButton("Yes", new DialogInterface.OnClickListener( ) { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Main.this.finish(); } }); bui1.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); AlertDialog ale1 = bui1.create(); ale1.show(); } }); }