当前位置:网站首页>About getfragmentmanager () and getchildfragmentmanager ()
About getfragmentmanager () and getchildfragmentmanager ()
2022-07-05 09:36:00 【Black Mountain demon 2018】
The first time a rookie writes a blog , Let's start with the problems encountered in the project
First, the problem arises
One activity It contains a fragment page , One fragment There are more than one fragment, The technology used is viewpager + fragment, First entry fragment No problem loading , The life cycle is also implemented . Because my project should activity Of launchMode yes singleTask Pattern , When entering this for the second time activity when ,viewpager Inside fragment There is a problem with loading , The life cycle is not implemented .
Problem solving
Later it was found that getFragmentManager() and getChildFragmentManager() The wrong use of the two methods leads to .
Look at the source
/** * Return the FragmentManager for interacting with fragments associated * with this fragment's activity. Note that this will be non-null slightly * before { @link #getActivity()}, during the time from when the fragment is * placed in a { @link FragmentTransaction} until it is committed and * attached to its activity. * * <p>If this Fragment is a child of another Fragment, the FragmentManager * returned here will be the parent's { @link #getChildFragmentManager()}. */ final public FragmentManager getFragmentManager() { return mFragmentManager; } /** * Return a private FragmentManager for placing and managing Fragments * inside of this Fragment. */ final public FragmentManager getChildFragmentManager() { if (mChildFragmentManager == null) { instantiateChildFragmentManager(); if (mState >= RESUMED) { mChildFragmentManager.dispatchResume(); } else if (mState >= STARTED) { mChildFragmentManager.dispatchStart(); } else if (mState >= ACTIVITY_CREATED) { mChildFragmentManager.dispatchActivityCreated(); } else if (mState >= CREATED) { mChildFragmentManager.dispatchCreate(); } } return mChildFragmentManager; }The source code comments are very clear getFragmentManager() The obtained manager is for fragment Attached to activity Speaking of , That is to say activity Inner management level 1 sub fragment What is used , If fragment There are also fragment, You should use getChildFragmentManager() Method , After modification, the problem is indeed solved .
边栏推荐
猜你喜欢
LeetCode 496. 下一个更大元素 I
Progressive JPEG pictures and related
Unity SKFramework框架(二十二)、Runtime Console 运行时调试工具
Wxml template syntax
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
[listening for an attribute in the array]
First understanding of structure
The most comprehensive promotion strategy: online and offline promotion methods of E-commerce mall
百度评论中台的设计与探索
小程序启动性能优化实践
随机推荐
Unity skframework framework (XXIII), minimap small map tool
OpenGL - Model Loading
2309. The best English letters with both upper and lower case
Community group buying exploded overnight. How should this new model of e-commerce operate?
Principle and performance analysis of lepton lossless compression
A keepalived high availability accident made me learn it again
How to choose the right chain management software?
Unity SKFramework框架(二十三)、MiniMap 小地图工具
Node の MongoDB Driver
[hungry dynamic table]
【饿了么动态表格】
Understanding of smt32h7 series DMA and DMAMUX
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
C form click event did not respond
2311. Longest binary subsequence less than or equal to K
C # draw Bezier curve with control points for lattice images and vector graphics
LeetCode 503. Next bigger Element II
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
What should we pay attention to when entering the community e-commerce business?
How to empty uploaded attachments with components encapsulated by El upload