Solving fragment overlap issues in apps

Source: Internet
Author: User

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

    • Android Fragment everything you should know

http://blog.csdn.net/lmj623565791/article/details/42628537

Solving fragment overlap issues in apps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.