点击back键 退出游戏。
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(KeyEvent.KEYCODE_BACK==keyCode)
{
//弹出警告提示框
Dialog dialog = new AlertDialog.Builder(this).setTitle("退出").setMessage("确认退出游戏?").setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
当前类名.this.finish();
//System.exit(0);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).create();
dialog.setCancelable(false);
dialog.show();
}
return false;
}