There is a ViewPager, in one of the tabs there is a base fragment, which, when initialized, instead of itself connects (replaces itself) another fragment.
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (savedInstanceState == null) { fragmentManager = getChildFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Log.d(LOG_TAG, "Init new fragment"); fragmentTransaction.replace(R.id.fragment_tab1, SearchFragment.newInstance(), getString(R.string.tag_tab_network)); fragmentTransaction.commit(); } else { Log.d(LOG_TAG, "Saved instance: " + savedInstanceState.toString()); } } If I ask the base fragment
@Override public void onCreate(@Nullable Bundle savedInstanceState) { setRetainInstance(true); super.onCreate(savedInstanceState); } then when the orientation is changed, the child fragment is not drawn, but the markup of the base fragment remains.
if
setRetainInstance(false); then everything is drawn normally (the child fragment is connected)
Question: why is this happening? In theory, it is necessary in such cases to restore the fragments, but how?