title: Navigate up by back button with Navigation Component
body: <p>I use navigation components to navigate from one fragment to another. However, when the user press the back button, I want to navigate back to first fragment. But it keep showing the second fragment. This is my nav_graph:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;navigation xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/nav_graph&quot;
      app:startDestination=&quot;@id/fragment1&quot;&gt;
      &lt;fragment
              android:id=&quot;@+id/fragment2&quot;
              android:name=&quot;com.myapp.ui.fragments.Fragment2&quot;
              android:label=&quot;fragment_2&quot; /&gt;
      &lt;fragment
              android:id=&quot;@+id/fragment1&quot;
              android:name=&quot;com.myapp.ui.fragments.Fragment1&quot;
              android:label=&quot;fragment_1&quot;&gt;
  
          &lt;action
                  android:id=&quot;@+id/action_fragment1_to_fragment2&quot;
                  app:destination=&quot;@id/fragment2&quot;
                  app:enterAnim=&quot;@anim/fragment_fade_enter&quot;
                  app:exitAnim=&quot;@anim/fragment_fade_exit&quot;
                  app:popUpTo=&quot;@id/fragment1&quot; /&gt;
      &lt;/fragment&gt;
  &lt;/navigation&gt;
  </code></pre>
  <p>And this is how I trigger the navigation in the code of my Fragment1-Class:</p>
  <pre><code> viewModel.itemSelected.observe(viewLifecycleOwner) {
          navigate(it)
      }
  </code></pre>
  <p>....</p>
  <pre><code>fun navigate(id: Long){
      val bundle = Bundle()
      bundle.putLong(&quot;itemid&quot;, id)    
      getNavController().navigate(R.id.action_fragment1_to_fragment2, bundle)
  }
  </code></pre>
  <p><strong>Edit:</strong>
  Corrected startDestination in XML.</p>
  <p><strong>Edit2:</strong>
  Added more code.</p>