title: ViewPager2 recreating fragments
body: <p>I have three fragments</p>
  <pre><code>MainFragment // Fragment with ViewPager2 
  
  ItemFragment // Fragment of the item of the adapter ViewPager2 that contains the RecyclerView 
  
  PreviewFragment // Fragment to which I navigate after clicking on any RecyclerView item in the ItemFragment
  </code></pre>
  <p>When I go <code>MainFragment -&gt; PreviewFragment</code> (exactly like that, not from ItemFragment) then on return back the <code>ItemFragment</code> is re-created from scratch. It is understandable because in <code>OnCreateView</code> I do this:</p>
  <pre><code>viewPager.adapter = MyAdapter(this)
  // Add items
  </code></pre>
  <p>Tried saving <code>MyAdapter</code> like this:</p>
  <pre><code>private val adapter: MyAdapter by lazy { 
      MyAdapter(this)
  }
  </code></pre>
  <p>But it leads to a <a href="https://stackoverflow.com/questions/61606656/viewpager2-crash">crash</a>, all the solutions described there did not help me.</p>
  <p>I also tried to save fragments anywhere, in any repository and cache them there and then add them, but this leads to a bunch of leaks in the LeakCanary of ViewPager2.</p>
  <p>In general, I would like to hear how this problem is solved, namely, you need to somehow save the state of the ViewPager2 items, perhaps they really need to be cached somewhere</p>
  <p>P.S  The main reason why the re-creation of fragments bothers me is that the scroll position of the RecyclerView gets lost</p>