Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All right, even though I moved to another way of doing things, I don't like to leave things incomplete...</p> <p>Going the way of the nested Fragments as suggested by Mark. The link posted in the comments goes to 404, but I found your <a href="https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/Nested" rel="noreferrer">example code</a> about nested fragments.</p> <p>A few things I've learned on the way:</p> <ul> <li><p>Nested fragments cannot have <code>setRetainInstance(true)</code>, or it will get:</p> <p>java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments</p></li> <li><p>It was a mistake to create a <code>FrameLayout</code> in the page of the <code>ViewPager</code> to hold the fragment. Looking in the Android code (and specifically the <code>FragmentPagerAdapter</code>), I should just use <code>container.getId()</code> to find where to add the <code>Fragment</code>. Looks like you cannot do anything more sophisticated at that level or it will break.</p></li> <li><p>From my understanding, if the fragments hold some information (like I do) that takes a long time to load, the different ways to handle this are:</p> <ul> <li>Use <code>onSaveInstanceState</code> (preferred way ?), but not possible if the Fragment is nested. The (empty) constructor will get called when needed by the framework.</li> <li>Use <code>setRetainInstance(true)</code>, in that case <code>savedInstanceBundle</code> is always <code>null</code>, but that Fragment (as Java object) will not be destroyed and it will still go through onAttach / onCreateView.</li> <li>Find some other way to save and restore what you need...</li> </ul></li> </ul> <p>Anyway, I pushed my solution using nested fragments on <a href="https://github.com/MatthieuLJ/fragment_layout" rel="noreferrer">github</a></p>
 

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