Because of the memory restart, the cause of frgament overlap, the reason is that fragmentstate does not save the display state of fragment, that is mHidden
, after the page restarts, the value is the default of false, that is, the show state, resulting in fragment overlap.
Then the solution is to write some code to save the fragment display state.
When a memory reboot occurs, the fragment will touchonSaveInstanceState方法,那么我们可以在这个方法内部去保存当前状态,然后在onCreate中进行取值回复,代码如下:
Public classBasefragmentextendsFragment {Private Static FinalString State_save_is_hidden = "State_save_is_hidden"; @Override Public voidonCreate (@Nullable Bundle savedinstancestate) {...if(Savedinstancestate! =NULL) { BooleanIssupporthidden =Savedinstancestate.getboolean (State_save_is_hidden); Fragmenttransaction ft=Getfragmentmanager (). BeginTransaction (); if(Issupporthidden) {ft.hide ( This); } Else{ft.show ( This); } ft.commit (); } @Override Public voidonsaveinstancestate (Bundle outstate) {Outstate.putboolean (State_save_is_hidden, Ishidden ()); }}
Reference Open Source project: Https://github.com/YoKeyword/Fragmentation
Reference article:
Fragment Full Analytic series (i): The pits that have been trampled for years
http://www.jianshu.com/p/d9143a92ad94
Fragment full Analytical Series (ii): Correct use Posture
Http://www.jianshu.com/p/fd71d65f0ec6
Fragment solutions for me: fragmentation
http://www.jianshu.com/p/38f7994faa6b
http://blog.csdn.net/lmj623565791/article/details/42628537
Solving fragment overlap issues in apps