简体   繁体   中英

Passing data from a adapter to fragment using startActivityForResult within same activity

I want to pass a data from my adapter class to another fragment with the help of startActivityForResult. If I used the below code same activity recreates it i don't want that. How to solve this issue?

Bundle mBundle = new Bundle();
mBundle.putString(Constants.SELECTED_PLOCATION, pLocation);
mBundle.putString(Constants.SELECTED_RLOCATION, rLocation);
mBundle.putString(Constants.SELECTED_FROM, selectedFrom);
mBundle.putString(Constants.FROM_TYPE, fromType);
mBundle.putString(Constants.AREA_TYPE, Constants.AREA);
getActivity().getFragmentManager().popBackStackImmediate();
Intent mIntent = new Intent(getActivity(), AuthorizedCustomerActivity.class);
getActivity().startActivityForResult(mIntent, PICK_LOCATION_REQUEST, mBundle);

Use below code for data transfer from adapter to fragment;

Fragment fragment = new YourFragmentName();
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();

Bundle mBundle= new Bundle();
mBundle.putString(Constants.SELECTED_PLOCATION, pLocation);
mBundle.putString(Constants.SELECTED_RLOCATION, rLocation);
mBundle.putString(Constants.SELECTED_FROM, selectedFrom);
mBundle.putString(Constants.FROM_TYPE, fromType);
mBundle.putString(Constants.AREA_TYPE, Constants.AREA);
fragment.setArguments(mBundle);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM