title: Navigation Controller (Managing Backstack) Jetpack Android
body: <p>Good day. So I've been working around with <strong>NavComponent</strong> of <strong>Jetpack</strong> for Android</p>
  <p>I've thought that management of <strong>BackStack</strong> of fragments had to be implemented there already, well in fact it is there but I have faced an issue.</p>
  <p>Here is my structure:</p>
  <p>I have and entry <em>Activity</em></p>
  <p>I have a <strong>NavHost</strong> in the <em>activity</em></p>
  <p>I have <strong>Bottom Navigation</strong> bar in the <em>Activity</em></p>
  <p>For each Bottom Item I am using separate Fragments to navigate through.</p>
  <p>Here is the code for the navigation.</p>
  <pre><code>     bottomNavigationView.setOnNavigationItemSelectedListener {
          when (it.itemId) {
              R.id.navigation_home -&gt; {
                  navController.apply {
                      navigate(R.id.navigation_home)
                  }
                  true
              }
              R.id.navigation_dashboard -&gt; {
                  navController.apply {
                      navigate(R.id.dashboardFragment)
                  }
                  true
              }
              R.id.navigation_notifications -&gt; {
                  true
              }
              else -&gt; {
                  false
              }
          }
      }
  </code></pre>
  <p><em>Never mind the last item.</em></p>
  <p>So the issue is next.</p>
  <p>If I try to switch between <strong>home</strong> and <strong>dashboard</strong> multiple times, when I press back then the stack surely will start popping all the items included there. So if I move like 6 times it will take me 12 attempts to actually exit the app.</p>
  <p>Currently I couldn't find any source where for example the <code>navigate()</code> method will accept some sort of argument to cash my fragments instead of recreating it each time and adding to the <strong>BackStack</strong>.</p>
  <p>So what kind of approach would you suggest?</p>
  <p>If I to manage the BackStack manually on each back button pressed, what's the purpose of <strong>NavController</strong> at all? Just for creating and <strong>FORWARD</strong> navigation?</p>
  <p>I think I'm missing some source in Android's official docs.</p>
  <p>Thank you beforehand.</p>
  <p>P.S.
  using <code>navController.popBackStack()</code> before calling <code>navigate()</code> surely isn't the correct choice.</p>