当前位置:网站首页>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 .
边栏推荐
- What are the advantages of the live teaching system to improve learning quickly?
- Analysis of eventbus source code
- Newton iterative method (solving nonlinear equations)
- Information and entropy, all you want to know is here
- H.265编码原理入门
- [sourcetree configure SSH and use]
- Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
- 阿里十年测试带你走进APP测试的世界
- Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
- [how to disable El table]
猜你喜欢

The most comprehensive promotion strategy: online and offline promotion methods of E-commerce mall

初识结构体

The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?

MySQL installation configuration and creation of databases and tables

VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置

【阅读笔记】图对比学习 GNN+CL

百度评论中台的设计与探索
![[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details

Applet global style configuration window

OpenGL - Coordinate Systems
随机推荐
Figure neural network + comparative learning, where to go next?
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
Composition of applet code
【阅读笔记】图对比学习 GNN+CL
云计算技术热点
基于宽表的数据建模应用
百度APP 基于Pipeline as Code的持续集成实践
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
Deep understanding of C language pointer
Thermometer based on STM32 single chip microcomputer (with face detection)
移动端异构运算技术-GPU OpenCL编程(进阶篇)
一篇文章带你走进cookie,session,Token的世界
揭秘百度智能测试在测试自动执行领域实践
顶会论文看图对比学习(GNN+CL)研究趋势
Applet data attribute method
植物大战僵尸Scratch
太不好用了,长文章加图文,今后只写小短文
H.265编码原理入门
Analysis of eventbus source code
Project practice | excel export function