区别 getChildFragmentManager getSupportFragmentManager

来源:互联网 发布:网络销售红酒好做吗 编辑:程序博客网 时间:2024/04/30 19:51

The definition of getChildFragmentManager() is:

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Meanwhile the definition of getFragmentManager() (or in this case getSupportFragmentManager()) is:

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

Basically, the difference is that Fragment's now have their own internal FragmentManager that can handle Fragments. The child FragmentManager is the one that handles Fragments contained within only the Fragment that it was added to. The other FragmentManager is contained within the entire Activity.

In this case, what I'm guessing is you've added the Fragments to the Activity's FragmentManager. You get the child FragmentManager which doesn't contain what you are looking for. Thus you get the exception because it can't find the Fragment with the given ID because it's in a different FragmentManager.


=============================================

mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity().getSupportFragmentManager());

在Fragment里面嵌套Fragment 的话,不要用上面的那句。。。会在ViewPager中出现。有些Fragment 不会加载的情况。。。既ViewPager 加载 Fragment 空白页的情况。。。。

【Android】java.lang.IllegalStateException: Recursive entry to executePendingTransactions  错误


所以   Fragment里面嵌套Fragment 的话:一定要用getChildFragmentManager();

  mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());


0 0