当前位置:网站首页>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 .
边栏推荐
- 使用el-upload封装得组件怎么清空已上传附件
- Gradientdrawable get a single color
- What should we pay attention to when entering the community e-commerce business?
- [ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
- 基于模板配置的数据可视化平台
- Hosting environment API
- Talking about the difference between unittest and pytest
- MySQL does not take effect in sorting string types
- LeetCode 496. Next larger element I
- Thermometer based on STM32 single chip microcomputer (with face detection)
猜你喜欢
[listening for an attribute in the array]
Progressive JPEG pictures and related
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Unity skframework framework (24), avatar controller third person control
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
How to choose the right chain management software?
Why do offline stores need cashier software?
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
【sourceTree配置SSH及使用】
How to improve the operation efficiency of intra city distribution
随机推荐
Priority queue (heap)
Creation and reference of applet
太不好用了,长文章加图文,今后只写小短文
LeetCode 556. 下一个更大元素 III
High performance spark_ Transformation performance
22-07-04 Xi'an Shanghao housing project experience summary (01)
A detailed explanation of the general process and the latest research trends of map comparative learning (gnn+cl)
Community group buying has triggered heated discussion. How does this model work?
一篇文章带你走进cookie,session,Token的世界
STM32简易多级菜单(数组查表法)
Explain NN in pytorch in simple terms CrossEntropyLoss
Shutter uses overlay to realize global pop-up
SMT32H7系列DMA和DMAMUX的一点理解
LeetCode 503. 下一个更大元素 II
OpenGL - Lighting
A keepalived high availability accident made me learn it again
C # image difference comparison: image subtraction (pointer method, high speed)
MySQL installation configuration and creation of databases and tables
百度交易中台之钱包系统架构浅析
顶会论文看图对比学习(GNN+CL)研究趋势