title: Fragments destroyed / recreated with Jetpack's Android Navigation components
body: <p>I'm trying to implement <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing" rel="noreferrer">Navigation with Jetpack's architecture components</a> in my existing app.</p>
  
  <p>I have a single activity app where the main fragment (<code>ListFragment</code>) is a list of items. Currently, when the user taps on a list item a second fragment is added to the stack by <code>fragmentTransaction.add(R.id.main, detailFragment)</code>. So when back is pressed the <code>DetailFragment</code> is detached and the <code>ListFragment</code> is shown again.</p>
  
  <p>With Navigation architecture this is handled automatically. Instead of adding the new fragment it's <a href="https://issuetracker.google.com/issues/109856764" rel="noreferrer">replaced</a>, so the fragment view is destroyed, <code>onDestroyView()</code> is called and <code>onCreateView()</code> is called when back is pressed to recreate the view.</p>
  
  <p>I understand that this is a good pattern used with <a href="https://developer.android.com/topic/libraries/architecture/livedata" rel="noreferrer">LiveData</a> and <a href="https://developer.android.com/reference/android/arch/lifecycle/ViewModel" rel="noreferrer">ViewModel</a> to avoid using more memory than necessary, but in my case this is annoying because the list has a complex layout and inflating it is time and CPU consuming, also because I'll need to save the scroll position of the list and scroll again to the same position user left the fragment. It's possible but seems it should exists a better way.</p>
  
  <p>I've tried to "save" the view in a private field on fragment and re-use it on <code>onCreateView()</code> if is already there, but it seems an anti-pattern.</p>
  
  <pre><code>private View view = null;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      if (view == null) {
          view = inflater.inflate(R.layout.fragment_list, container, false);
          //...
      }
  
      return view;
  }
  </code></pre>
  
  <p>Is there any other, more elegant, way to avoid re-inflating the layout?</p>