1.A-Activity首先携带数据跳转B-Activity
Intent intent = new Intent();
intent.setClass(getActivity(), MedicineActivity.class);
intent.putExtra("medicineList", (Serializable) medicineList);
intent.putExtra("code", 101);
startActivityForResult(intent, 101);
2.接收A-Activity的数据,把处理完的数据setResult带着code,为了区别.
Intent intent = getIntent();
medicineList = (List<ModelMedicine>) intent.getSerializableExtra("medicineList");
code = intent.getIntExtra("code", 0);
Intent intent = new Intent().putExtra("name", name);
setResult(code, intent);
3.最后在你需要处理返回的数据的界面进行重写获取数据
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 100){
String name = data.getStringExtra("name");
temporaryDoctorAdviceFragment.setMedicine(name);
}
if (resultCode == 101){
String name = data.getStringExtra("name");
longTimeDoctorAdviceFragment.setMedicine(name);
}
}
代码很简单,有什么不好理解了的一起探讨~