Activity A 中绑定数据跳转到B
final Intent intent =new Intent();
final Bundle bundle=new Bundle();
bundle.putString("isSettlementActivity","isSettlementActivity");
intent.putExtras(bundle);
intent.setClass(AActivity.this, BActivity.class);
startActivityForResult(intent,22);
Activity B中回传数据时采用setResult方法,并且之后要调用finish方法
String s=getIntent().getSerializableExtra("isSettlementActivity");//获取到的A数据
final Intent i=new Intent();
i.putExtra("shName",showAddressBean.getName());
setResult(22, i);/intent为A传来的带有Bundle的intent,当然也可以自己定义新的Bundlefinish()
finish();//此处一定要调用
Activity A中重写方法
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (22 == requestCode) {
Toast(data.getStringExtra("shName"));
}
}
网友评论