标签:dia ret sage 返回 cte lse his log OLE
// 第一种
public boolean onKeyDown(int keyCode, KeyEvent event) {
// 按下键盘上返回按钮
if (keyCode == KeyEvent.KEYCODE_BACK) {
new AlertDialog.Builder(this)
.setMessage("确定退出系统吗?")
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
})
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
finish();
}
}).show();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
//直接退出程序
@Override
protected void onDestroy() {
super.onDestroy();
// 或者下面这种方式
//System.exit(0);
//建议用这种
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);
}
// 第三种
@Override
public void onBackPressed() {
super.onBackPressed();
}
标签:dia ret sage 返回 cte lse his log OLE
原文地址:https://www.cnblogs.com/yxfcnbg/p/11441797.html