4

Here is my problem.

I'm basically working with a fragment containing some informations about a place, and a list of all the other places in the same city. By clicking on one of the element of the list, you can access an other instance of the same fragment with the information related to the element you have clicked.

The problem is, if two fragment containing the information of a same place are contained in the backstack, the backstack doesnt work anymore.

This is how I create a new fragment:

Bundle bundle = new Bundle();
                    bundle.putString("some data", "some data");
                    Fragment contentFragment = new CoreFragment(id);
                    contentFragment.setArguments(bundle);
                    FragmentManager fm = getActivity().getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fm.beginTransaction();
                    fragmentTransaction.replace(R.id.actmain_core, contentFragment, "corefragment");
                    fragmentTransaction.addToBackStack(contentFragment.getClass().getName());
                    fragmentTransaction.commit();

It works perfectly if all the fragment use different data. However if I add a fragment to the backstack with data already used in a fragment present in the backstack, when I will press the back button to access it, it will not be displayed.

How can I fix this problem? How can I manage the case where a fragment and its exact copy are present in the backstack but need to be differentiated?

Virthuss
  • 3,142
  • 1
  • 21
  • 39

0 Answers0