Android how to put a dialog box after pressing a back button?

Public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent. KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super. OnKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.

Builder(this) . SetMessage("Do you want to exit application? ") .

SetPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { finish(); //close(); } }) . SetNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { } }) .show(); }.

Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode! = KeyEvent. KEYCODE_BACK) return super.

OnKeyDown(keyCode, event); DialogInterface. OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface. BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.

BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog. Builder builder = new AlertDialog. Builder(this); builder.

SetMessage("Are you sure? "). SetPositiveButton("Yes", dialogClickListener) .

SetNegativeButton("No", dialogClickListener).show(); return super. OnKeyDown(keyCode, event); }.

Try this... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent. KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog. Builder(this).create(); alertDialog.

SetTitle("Exit Alert"); alertDialog. SetIcon(R.drawable. Appicon); alertDialog.

SetMessage("Do you really want to exit the Game? "); alertDialog. SetButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.

SetButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super. OnKeyDown(keyCode, event); }.

AlertDialog alertbox = new AlertDialog. KEYCODE_BACK) return super. Builder builder = new AlertDialog.

SetMessage("Are you sure?"). If (keyCode == KeyEvent. AlertDialog alertDialog = new AlertDialog.

Terms of service. Not the answer you're looking for?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions