Android中退出程序的提示框
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
- dialog();
- return true;
- }
- return true;
- }
- protected void dialog() {
- AlertDialog.Builder builder = new Builder(AccoutList.this);
- builder.setMessage("确定要退出吗?");
- builder.setTitle("提示");
- builder.setPositiveButton("确认",
- new android.content.DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- //AccoutList.this.finish();
- //System.exit(1);
- android.os.Process.killProcess(android.os.Process.myPid());
- }
- });
- builder.setNegativeButton("取消",
- new android.content.DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- builder.create().show();
- }
from:http://blog.csdn.net/jumping_android/article/details/7571309