当前位置:网站首页>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 .
边栏推荐
- It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
- Applet data attribute method
- 小程序启动性能优化实践
- c语言指针深入理解
- 【sourceTree配置SSH及使用】
- Figure neural network + comparative learning, where to go next?
- 图神经网络+对比学习,下一步去哪?
- Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
- 使用el-upload封装得组件怎么清空已上传附件
- 百度智能小程序巡检调度方案演进之路
猜你喜欢
百度评论中台的设计与探索
代码语言的魅力
H.265编码原理入门
Kotlin introductory notes (II) a brief introduction to kotlin functions
Kotlin introductory notes (VIII) collection and traversal
Unity SKFramework框架(二十三)、MiniMap 小地图工具
基于模板配置的数据可视化平台
LeetCode 31. 下一个排列
移动端异构运算技术-GPU OpenCL编程(进阶篇)
Using request headers to develop multi terminal applications
随机推荐
Explain NN in pytorch in simple terms CrossEntropyLoss
SMT32H7系列DMA和DMAMUX的一点理解
The most comprehensive promotion strategy: online and offline promotion methods of E-commerce mall
一篇文章带你走进cookie,session,Token的世界
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
OpenGL - Lighting
C # compare the differences between the two images
How to choose the right chain management software?
Applet global style configuration window
Applet customization component
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Uni app implements global variables
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
太不好用了,长文章加图文,今后只写小短文
MySQL does not take effect in sorting string types
OpenGL - Model Loading
Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
How do enterprises choose the appropriate three-level distribution system?
植物大战僵尸Scratch
How to empty uploaded attachments with components encapsulated by El upload