当前位置:网站首页>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 .
边栏推荐
- [JS sort according to the attributes in the object array]
- 【饿了么动态表格】
- Figure neural network + comparative learning, where to go next?
- Android privacy sandbox developer preview 3: privacy, security and personalized experience
- 【对象数组的排序】
- How to empty uploaded attachments with components encapsulated by El upload
- LeetCode 496. 下一个更大元素 I
- 使用el-upload封装得组件怎么清空已上传附件
- OpenGL - Coordinate Systems
- Community group buying has triggered heated discussion. How does this model work?
猜你喜欢
22-07-04 Xi'an Shanghao housing project experience summary (01)
LeetCode 496. Next larger element I
How to empty uploaded attachments with components encapsulated by El upload
C form click event did not respond
OpenGL - Model Loading
Newton iterative method (solving nonlinear equations)
Understanding of smt32h7 series DMA and DMAMUX
How to improve the operation efficiency of intra city distribution
【阅读笔记】图对比学习 GNN+CL
Wxss template syntax
随机推荐
C # image difference comparison: image subtraction (pointer method, high speed)
我的一生.
Talking about label smoothing technology
What about wechat mall? 5 tips to clear your mind
云计算技术热点
Alibaba cloud sends SMS verification code
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Hosting environment API
Gradientdrawable get a single color
Deep understanding of C language pointer
Lepton 无损压缩原理及性能分析
[two objects merged into one object]
2311. Longest binary subsequence less than or equal to K
SMT32H7系列DMA和DMAMUX的一点理解
Android privacy sandbox developer preview 3: privacy, security and personalized experience
小程序启动性能优化实践
使用el-upload封装得组件怎么清空已上传附件
Principle and performance analysis of lepton lossless compression
E-commerce apps are becoming more and more popular. What are the advantages of being an app?
图神经网络+对比学习,下一步去哪?