当前位置:网站首页>How to determine fragment restored from Backstack
How to determine fragment restored from Backstack
2022-06-12 20:09:00 【Superior virtue and weak water】
problem :
Been searching for this issue for a while to no avail now: I've been looking for this problem, but it doesn't help now :
How to determine fragment is being restored from backstack? How to determine if a clip is from backstack recovery ?I'm using the compatibility library and a ListFragment inside a FragmentActivity. I am here FragmentActivity Compatibility libraries and ListFragment.When an item inside ListFragment is selected, a new Fragment is started to replace the ListFragment. choice ListFragment Project in , A new fragment will be launched to replace ListFragment.
I noticed that when the FragmentActivity gets paused, the Fragment's onSaveInstanceState is called. I noticed when FragmentActivity When suspended , Would call Fragment Of onSaveInstanceState.But when the Fragment is put into the back stack via FragmentTransaction, onSaveInstanceState doesn't get called, then the lifecycle methods onCreateView and onActivityCreated gets called with null savedInstanceState Bundle. But when Fragment adopt FragmentTransaction When put into the background stack ,onSaveInstanceState Will not be called , So use null savedInstanceState Bundle Call lifecycle method onCreateView and onActivityCreated.
I'm asking this because I want to load some data when the Fragment is created or restored, but not so when user comes back via. I ask this because I want to create or restore Fragment Load some data , But this is not the case when the user comes back through it .backstack. In the stack .
I've looked at How to check if Fragment was restored from a backstack? I have ever seen How to check whether a fragment is recovered from the background ?but want to add more details in hopes this would incite an answer. But I hope to add more details , Hopefully this will lead to the answer .
Edit: just noticed http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle) says edit : Just noticed http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle) say
Note however: this method may be called at any time before onDestroy(). But please pay attention to : Can be in onDestroy() Call this method any time before .There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state. in many instances , Most of the fragments may have been removed ( For example, placed in a place that does not display UI On the background stack of ), But before the activity it owns actually needs to save its state , Its state will not be saved .
So onSaveInstanceState is definitely out of the question... therefore onSaveInstanceState Absolutely impossible ......
Solution :
Reference resources : https://stackoom.com/en/question/XEGn边栏推荐
- 4 R basic exercises
- Test prerequisites: recommend a special cross platform app performance test tool!
- Implementation of exec function and shell
- Niuke.com: sum of three numbers
- Wechat jsapi payment pit summary
- Operating instructions for installing mysql5.7 in centos7
- Is online futures account reliable? Is it safe to open an online futures account?
- exec函数、shell的实现
- If you master these skills, you can also write a high score resume in the eyes of HR
- 【splishsplash】自定义导出器
猜你喜欢

I learned database at station B (10): View

Understanding of data in memory

Understand Jack Dorsey's web5 from the ppt on page 16

Niuke.com: sum of three numbers

Demand and business model innovation - demand 1 - Introduction to demand engineering

Overview of object detection

开源深度学习框架PlaidML安装及测试

The joint empowerment plan of Baidu PaddlePaddle large enterprise open innovation center was launched! Help Pudong to upgrade its industry intelligently

How to close icloud when Apple ID of Apple mobile phone forgets password and frequently jumps out to log in

Alipay payment episode 11: monitoring after successful payment callback
随机推荐
What is a hash index?
Test prerequisites: recommend a special cross platform app performance test tool!
[notes for question brushing] line segment tree
system()
Using / developing private plug-ins in traifik proxy 2.5 (traifik official blog)
Microsoft Word 教程,如何在 Word 中插入页眉或页脚?
Reading applet based on wechat e-book graduation design (2) applet function
Since using low code development, the development efficiency has been increased by 10 times
Equipment management - borrowing and returning module 1
MySQL index classification
Detailed explanation of search tree and hash table
I learned database at station B (10): View
What is the difference between union and union all
Index optimization principle
Demand and business model innovation - demand 2- demand basis
PostgreSQL数据库复制——后台一等公民进程WalReceiver pg_stat_wal_receiver视图
WordPress station group tutorial automatic collection of pseudo original release tutorial
Unsupported class file major version 60
How do indexes match?
Generate API documents using swagger (go language example)
