当前位置:网站首页>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 .
边栏推荐
- [object array A and object array B take out different elements of ID and assign them to the new array]
- My life
- 阿里十年测试带你走进APP测试的世界
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- 微信小程序获取住户地区信息
- 测试老鸟浅谈unittest和pytest的区别
- LeetCode 31. 下一个排列
- SQL learning group by multi table grouping scenario
- 百度APP 基于Pipeline as Code的持续集成实践
- Svgo v3.9.0+
猜你喜欢
Node collaboration and publishing
Unity skframework framework (24), avatar controller third person control
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
SQL learning - case when then else
OpenGL - Coordinate Systems
SMT32H7系列DMA和DMAMUX的一点理解
百度交易中台之钱包系统架构浅析
How to choose the right chain management software?
基于宽表的数据建模应用
随机推荐
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
LeetCode 503. Next bigger Element II
AUTOSAR from getting started to mastering 100 lectures (103) -dbc file format and creation details
uni-app---uni.navigateTo跳转传参使用
百度智能小程序巡检调度方案演进之路
7 月 2 日邀你来TD Hero 线上发布会
Kotlin introductory notes (III) kotlin program logic control (if, when)
Lepton 无损压缩原理及性能分析
Go 语言使用 MySQL 的常见故障分析和应对方法
SMT32H7系列DMA和DMAMUX的一点理解
MySQL does not take effect in sorting string types
What are the advantages of the live teaching system to improve learning quickly?
Shutter uses overlay to realize global pop-up
[hungry dynamic table]
H.265编码原理入门
基于宽表的数据建模应用
OpenGL - Lighting
[sourcetree configure SSH and use]
What should we pay attention to when entering the community e-commerce business?
Applet global style configuration window