android硬件返回
1.第一种
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
//点击回退键
if(KeyEvent.KEYCODE_BACK==keyCode) {
//显示一个警告框
new AlertDialog.Builder(MainActivity.this)
.setMessage("你确定要退出吗?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//退出
finish();
}
})
.setNegativeButton("取消", null)
.show();
return true;
}
return super.onKeyUp(keyCode, event);
}
2.第二种
@Override
public void onBackPressed() {
if(changed){
Intent intent=new Intent();
intent.putStringArrayListExtra("imagelist", imageList);
setResult(RESULT_CODE,intent);
}
super.onBackPressed();
}