Note that there are some explanatory texts on larger screens.

plurals
  1. POBack key to pop the Fragment shows overlapping fragments
    text
    copied!<p>I created a sample app to test this overlapping issue. </p> <p>I have a fragment type, Fragment1, and I create a new instance of Fragment1 and add it to a FrameLayout in my activity at runtime. I add the fragment with the help of a few buttons.</p> <p>Note: I have given each new instance of Fragment1 a different number(#1, #2, #3, etc.) to display on the UI to help me figure out which fragment I am viewing.</p> <p>So.. here is what I do:</p> <ol> <li>Click on Button 3, create new instance of Fragment1 and add it to Frame1.</li> <li>Click on Button 4, create new instance of Fragment1 and add it to Frame1 and add it to the fragment backstack.</li> <li>Repeat 1 and 2.</li> <li>Repeat 1 and 2.</li> </ol> <p>Now, I have fragments in this order: 1(#1),2(#2),1(#3),2(#4),1(#5),2(#6).</p> <p>I press the back key when viewing fragment #6.</p> <ol> <li>Back key press, UI displays (#5).</li> <li>Back key press, UI displays (#3 AND #5),</li> <li>Back key press, UI displays (#1, #3, AND #5)</li> </ol> <p>It seems fragments are getting displayed ON TOP of each other.</p> <p>WHY? Is there an overlapping issue? How can I clear out this overlapping issue. I thought this would be an issue on the compatibility library... but it is also on 3.0. </p> <p>Code for adding fragments:</p> <pre><code>public int doFragmentChange(int cont1, Fragment frag1, String tag1, int cont2, Fragment frag2, String tag2, boolean addToStack, String stackTag) { FragmentManager fm = getFragmentManager();// getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); if (frag1 != null) { ft.replace(cont1, frag1, tag1); } if (frag2 != null) { ft.replace(cont2, frag2, tag2); } // add fragment to stack if (addToStack) ft.addToBackStack(stackTag); return ft.commit(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload