title: Navigation Component - Starting destination is incorrect
body: <p>I started noticing something in my app the other day and its wildly inconsistent. Sometimes it happens and sometimes it doesn't.</p>
  <p>I am using the Navigation Component to handle navigation in the app and I started noticing that sometimes, when popping the backstack via the action bar back button or the device back button, it returns to a fragment that is no longer the starting destination (or at least shouldn't be).</p>
  <p>In my case the app starts in MainFragment and once authenticated moves to DashboardFragment. This is a pretty common scenario.</p>
  <p>Navigation in the app is pretty flat. most of the time its only 1 level deep so nearly all views are accessible from the dashboard.</p>
  <p>The app starts at a login view as many do and then to a dashboard where the session will remain as the &quot;start destination&quot;. To accomplish this, its done in the nav_graph using popUpTo and popUpToInclusive.</p>
  <pre><code>&lt;fragment
      android:id=&quot;@+id/mainFragment&quot;
      android:name=&quot;com.example.view.fragments.MainFragment&quot;
      android:label=&quot;Welcome&quot;&gt;
      &lt;action
          android:id=&quot;@+id/action_mainFragment_to_dashboardFragment&quot;
          app:destination=&quot;@id/dashboardFragment&quot;
          app:popUpTo=&quot;@id/mainFragment&quot;
          app:popUpToInclusive=&quot;true&quot;/&gt;
  &lt;/fragment&gt;
  
  &lt;fragment
      android:id=&quot;@+id/dashboardFragment&quot;
      android:name=&quot;com.example.view.fragments.dashboard.DashboardFragment&quot;
      android:label=&quot;@string/dashboard_header&quot; &gt;
      &lt;action
          android:id=&quot;@+id/action_dashboardFragment_to_notificationsFragment&quot;
          app:destination=&quot;@id/notificationsFragment&quot; /&gt;
  &lt;/fragment&gt;
  </code></pre>
  <p>When the user successfully authenticates and its time to go to the dashboard, I use NavController.navigate() to send them there.</p>
  <pre><code>findNavController().navigate(
      MainFragmentDirections.actionMainFragmentToDashboardFragment()
  )
  
  // This should have the same result and it does appear to be affected by the same issue
  // findNavController().navigate(R.id.action_mainFragment_to_dashboardFragment)
  </code></pre>
  <p>I have an action bar with a back arrow and a navigation drawer. In the main activity I need to define the AppBarConfiguration and override onSupportNavigateUp()</p>
  <pre><code>lateinit var appBarConfiguration: AppBarConfiguration
  ...
  override fun onCreate(savedInstanceState: Bundle?) {
      Timber.d(&quot;onCreate()&quot;)
      super.onCreate(savedInstanceState)
  
      _binding = ActivityMainBinding.inflate(layoutInflater)
      setContentView(binding.root)
  
      // There is 2 different drawer menu's respectfully.
      appBarConfiguration = AppBarConfiguration(
          setOf(
              R.id.mainFragment,
              R.id.dashboardFragment
          ), binding.drawerLayout
      )
  
      setSupportActionBar(binding.toolbar)
      setupActionBarWithNavController(navController, appBarConfiguration)
  }
  ...
  override fun onSupportNavigateUp(): Boolean {
      Timber.d(&quot;-&gt; onSupportNavigateUp()&quot;)
      val breadcrumb = navController
          .backStack
          .map { it.destination }
          .filterNot { it is NavGraph }
          .joinToString(&quot; &gt; &quot;) { it.displayName.split('/')[1] }
  
      Timber.d(&quot;Backstack: $breadcrumb&quot;)
      Timber.d(&quot;Previous backstack entry: ${navController.previousBackStackEntry?.destination?.displayName}&quot;)
  
      return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
  }
  ...
  </code></pre>
  <p>The logs look like this when we step back and it is <em>working correctly</em></p>
  <pre><code>D/MainActivity: -&gt; onSupportNavigateUp()
  D/MainActivity: Backstack: dashboardFragment &gt; testingFragment
  D/MainActivity: Previous backstack entry: com.example:id/dashboardFragment
  D/DashboardFragment: -&gt; onCreateView()
  D/BaseFragment: -&gt; onCreateView()
  D/DashboardFragment: -&gt; onViewCreated()
  </code></pre>
  <p>I also noticed when using the hamburger in the action bar that it also calls onSupportNavigateUp()</p>
  <pre><code>D/MainActivity: -&gt; onSupportNavigateUp()
  D/MainActivity: pendingAction: false
  D/MainActivity: Backstack: dashboardFragment
  D/MainActivity: Previous backstack entry: null
  </code></pre>
  <p>When I use the drawer to navigate to a destination I do see this in the logs and im not sure where/why this is returned or if it has any importance</p>
  <pre><code>I/NavController: Ignoring popBackStack to destination com.example:id/mainFragment as it was not found on the current back stack
  </code></pre>
  <p>Now, when its <em>NOT</em> working correctly, this is what the logs look like</p>
  <pre><code>D/MainActivity: -&gt; onSupportNavigateUp()
  D/MainActivity: Backstack: mainFragment &gt; testingFragment
  D/MainActivity: Previous backstack entry: com.example:id/mainFragment
  D/MainFragment: -&gt; onCreateView()
  D/BaseFragment: -&gt; onCreateView()
  D/MainFragment: -&gt; onViewCreated()
  </code></pre>
  <p>This really feels like the popUpTo and popUpToInclusive properties are not being applied (sometimes) when performing the navigation from main fragment to dashboard fragment. It's also suspicious that even though the dashboard fragment is not set as the new starting destination but also its missing from the backstack. Assuming the properties were NOT applied I would expected to see the breadcrumb <code>Backstack: mainFragment &gt; dashboardFragment &gt; testingFragment</code></p>
  <p>Any help would be greatly appreciated!</p>