//1.startActivityForResult方式启动BActivity
Intent intent = new Intent(AActivity.this, BActivity.class); startActivityForResult(intent, 1);//1是启动BActivity的请求码////2.重写onActivityResult方法
protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); //确认是B返回到A的 if(requestCode == 1 && resultCode == 11){ boolean buttonIsClicked = data.getBooleanExtra("buttonIsClicked", false); if(buttonIsClicked){ Toast.makeText(this, "buttonIsClicked", Toast.LENGTH_LONG).show(); } //做相关操作 } }第二步(BActivity里面):
//监听BActivity中的按返回事件,设置结果码
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { intent = new Intent(); intent.putExtra("buttonIsClicked", isClick); BActivity.this.setResult(11, intent);//11是结果码 BActivity.this.finish(); } return super.onKeyDown(keyCode, event); }