在当前片段 中 AddNewAccountFragment
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == Constants.CHOOSE_BANK_REQUEST_CODE) {
bankName = data.getStringExtra("BANK_NAME");
if (!TextUtils.isEmpty(bankName)) {
mChooseBankEdittext.setText(bankName);
mReceivedBankName = bankName;
}
}
}
}
// if sending data from next fragment to previous fragment using OnActivityResult.
在 OnResume 中的Edittext上的 setText 。
@Override
public void onResume() {
super.onResume();
mChooseBankEdittext.setText(bankName);
}
在目标片段 中选择银行名称片段
在 Fragment 中的 onClick() 下面执行
Intent intent = new Intent(getActivity(), AddNewAccountFragment.class);
intent.putExtra("BANK_NAME", bankName);
if (getFragmentManager().findFragmentByTag("AddNewAccountFragment") != null)
getFragmentManager().findFragmentByTag("AddNewAccountFragment").onActivityResult(Constants.CHOOSE_BANK_REQUEST_CODE, RESULT_OK, intent);
getActivity().getSupportFragmentManager().popBackStack();