一切福田,不離方寸,從心而覓,感無不通。

Android中退出程序的提示框

  1. @Override
  2.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  3.         if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  4.             dialog();
  5.             return true;
  6.         }
  7.         return true;
  8.     }
  1. protected void dialog() {
  2.         AlertDialog.Builder builder = new Builder(AccoutList.this);
  3.         builder.setMessage("确定要退出吗?");
  4.         builder.setTitle("提示");
  5.         builder.setPositiveButton("确认",
  6.         new android.content.DialogInterface.OnClickListener() {
  7.             @Override
  8.             public void onClick(DialogInterface dialog, int which) {
  9.                 dialog.dismiss();
  10.                 //AccoutList.this.finish();
  11.                 //System.exit(1);
  12.                 android.os.Process.killProcess(android.os.Process.myPid());
  13.             }
  14.         });
  15.         builder.setNegativeButton("取消",
  16.         new android.content.DialogInterface.OnClickListener() {
  17.             @Override
  18.             public void onClick(DialogInterface dialog, int which) {
  19.                 dialog.dismiss();
  20.             }
  21.         });
  22.         builder.create().show();
  23.     }

 

from:http://blog.csdn.net/jumping_android/article/details/7571309