Solve the problem that FragmentManager is already executing transactions

When using viewpager+tablayout+ fragment for fragment nesting or ViewPager2 nesting ViewPager2

Will report an error FragmentManager is already executing transactions

Possible reason: when using the setadapter of the viewpager in the fragment
, getActivity().getSupportFragmentManager is used , which will conflict with the parent activity at this time, it should be: getChildFragmentManager,

When the Activity initializes FragmentTabHost, a fragmentmanager is passed in, which is obtained by getFragmentManager, because the tabhost needs to interact with the fragment of the first layer, which directly interacts with the activity

As for the nested viewpager in Fragment1, because it is the nested Fragment that needs to interact, it needs to get the ChildFragmentManager.

The solution is as follows:
Our fragment is controlled by fragmentmanager, which should be controlled by fragmentmanager in the first-level nesting, and fragmentchildmanager should be used in the second-level fragment.
When controlling the second-level fragment, be careful not to nest the second-level fragment The first-level fragment is added to the fragmentchildmannager, otherwise this problem will occur

   --to: Ly
 

Supongo que te gusta

Origin blog.csdn.net/Jason_HD/article/details/130242794
Recomendado
Clasificación