Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to do this by caching the Fragments as I added them in my own ArrayList. Then I set up an OnBackStackChangedListener to keep track of which one was shown and pop off the ArrayList as necessary.</p> <p>My purpose was a little different but the code below should be what you need for what you describe. The tags are so you can have multiple back stacks if you need. It won't compile as-is (I've clipped lots of my own code) but should give you an idea of how I did it. Additional disclaimer: I <strong>just</strong> got this working and there may be issues I haven't hit yet.</p> <pre><code> public void replaceFragmentWithBackStackForTag(Fragment fragment, String tag) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.detach(visibleFragment); ft.add(R.id.realtabcontent, fragment, tag); ft.attach(fragment); ft.addToBackStack(null); manualBackStacks.get(tag).add(fragment); ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } </code></pre> <p>The code you'll want where your activity gets recreated after an orientation change:</p> <pre><code> ArrayList&lt;Fragment&gt; backStack = new ArrayList&lt;Fragment&gt;(manualBackStacks.get(tag)); popArrayListToIndex(manualBackStacks.get(tag), 0); // helper I wrote for (int bs = 1; bs &lt; backStack.size(); bs++) { replaceFragmentWithBackStackForTag(backStack.get(bs), tag); } </code></pre> <p>The backstack listener:</p> <pre><code> public void onBackStackChanged() { int index = getSupportFragmentManager().getBackStackEntryCount(); ArrayList&lt;Fragment&gt; backStack = manualBackStacks.get(tag); visibleFragment = backStack.get(index); // Pop the last element if we've backed up. popArrayListToIndex(backStack, index); } </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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