// 第一种
public boolean onKeyDown(int keyCode, KeyEvent event) {
// press the back button on the keyboard
IF (keyCode == KeyEvent.KEYCODE_BACK) {
new new AlertDialog.Builder (the this)
.setMessage ( "OK to exit the system do?")
.SetNegativeButton ( "Cancel",
new new DialogInterface.OnClickListener () {
void the onClick public (DialogInterface Dialog,
int Which) {
}
})
.setPositiveButton ( "OK",
new new DialogInterface.OnClickListener () {
public void the onClick (DialogInterface Dialog,
int whichButton) {
Finish ();
}
}).show();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
// Exit the program directly
@Override
protected void onDestroy () {
super.onDestroy ();
// this manner or following
//System.exit(0);
// this suggested
android.os.Process.killProcess (android .os.Process.myPid ());
}
// 第二种
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
return true;
}
return super.onKeyDown(keyCode, event);
}
// third
@Override
public void onBackPressed () {
super.onBackPressed ();
}