I'm trying to understand the bad behavior in fragments: methods onCreateViewand onActivityCreatedare called even a fragment, which is not "visible" in the layout.
If you use the code:
TestFragment testFragment = new TestFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragmentDetail, testFragment, "test");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
replacing FrameLayout with the fragment identifierDetail with the fragment, and then you rotate the device, the fragment method is still called, even if the container is no longer in the portrait layout. This does not happen if you use the 'static' tag <fragment>. If you use a static fragment, fragment methods are called only when the fragment appears. Is it possible to achieve the same behavior without using a fragment tag? I need a way to avoid rendering a fragment if it is not in the layout.
thank
source
share