How to avoid this?
This is my code to go from one Fragment to another
Fragment fragment = new PerfilFragment();
Bundle bundle = new Bundle();
bundle.putInt("user_id", 1);
fragment.setArguments(bundle);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.nav_host_fragment,fragment,null);
fragmentTransaction.commit();
In snippet management do replace instead of add
Change this:
For this:
Also don't use the fragment tag by assigning it an initial fragment because for some reason it doesn't replace it afterwards (I think it's because it does it in a different session when you start the application).