[代码]捕获返回键,弹出是否确定返回应用MainMenu的对话框
捕获返回键,弹出是否确定返回应用MainMenu的对话框
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle(R.string.app_name)
.setMessage(R.string.quit_desc)
.setNegativeButton(R.string.quit_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton(R.string.quit_confirm, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent myIntent;
myIntent = new Intent(PictureScribble.this, MainMenu.class);
startActivity(myIntent);
PictureScribble.this.finish();
}
}).show();
return true;
}else{
return super.onKeyDown(keyCode, event);
}
}