public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(1, 1, 1, "退出").setIcon(R.drawable.exit);
menu.add(2, 2, 2, "关于").setIcon(R.drawable.about);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == 1){
//SysApplication.getInstance().exit();
new AlertDialog.Builder(this).setMessage("您确定要退出").
setPositiveButton("确定",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface ,int i){
SysApplication.getInstance().exit() } }
).setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface ,int i){
} }).show();}
else if(item.getItemId() == 2){
Toast.makeText(this, "关于",Toast.LENGTH_SHORT).show();
}
return true; }
@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
//按下键盘上返回按钮
if(keyCode == KeyEvent.KEYCODE_BACK){
new AlertDialog.Builder(this).setMessage("您确定要退出").
setPositiveButton("确定",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface ,int i){
SysApplication.getInstance().exit();} }
).setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface ,int i){
}}).show();
} return
false;}
解决方案:将红色字体处返回true,改为false;