I am using android jetpack navigation in my project. So I have an activity and multiple fragments. I realize that if I create an object in fragment a and pass it to fragment b when I change the object field value in fragment b and turn back to fragment a with onbackpressed() method the object in fragment a is not updated. However, if I pass the same object from fragment b to fragment c end change the object field value in fragment c and turn back to fragment b then the object data in fragment b is updated. So what is the difference here?
Fragment A
Product prd = new Product();
prd.setId(Utils.getRandomString(6));
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.EXTRA_PRODUCT, prd);
newPrd.setOnClickListener((v) -> navController.navigate(R.id.action_navigation_dashboard_to_productEditorFragment, bundle));
Fragment B
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getArguments() != null) {
product = getArguments().getParcelable(Constants.EXTRA_PRODUCT);
if (product != null) {
fillViews(product);
}
}}
private void sendObjectToFragmentC() {
Bundle bundle = new Bundle();
if (product!= null)
bundle.putParcelable(Constants.EXTRA_PRODUCT, product);
navController.navigate(R.id.action_productEditorFragment_to_tagSelectFragment, bundle);
}
Fragment C
if (getArguments() != null) {
product = getArguments().getParcelable(Constants.EXTRA_PRODUCT);
if (product != null) {
fillViews(product);
}
}