在android开发中,当不满足触发条件就按返回键的时候,就要对此进行检测。尤其是当前Activity需要往前一个Activity传送消息时。即Activity1跳转到Activity3如果采用的是startActivityForResult这种方式,如果不重写返回键,程序不知道要返回给Activity1什么内容就会报错。因此,必须对Activity3的返回按键重写,这里让他传一个“ERROR”信息:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent backIntent = new Intent(Activity3.this, Activity1.class);
Bundle bundle = new Bundle();
if(!clickOk)
bundle.putString("send", "ERROR");
backIntent.putExtras(bundle);
Activity3.this.setResult(1, backIntent);
Activity3.this.finish();
//super.onBackPressed();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent backIntent = new Intent(Activity3.this, Activity1.class);
Bundle bundle = new Bundle();
if(!clickOk)
bundle.putString("send", "ERROR");
backIntent.putExtras(bundle);
Activity3.this.setResult(1, backIntent);
Activity3.this.finish();
//super.onBackPressed();
}