title: How can I back from the second fragment to the first fragment using Navigation Component?
body: <p>How can I back from the second fragment to the first fragment using Navigation Component?</p>
  <p><strong>navigation_main.xml</strong></p>
  <pre><code>&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/main_navigation&quot;
      app:startDestination=&quot;@id/firstFragment&quot;&gt;
  
      &lt;fragment
          android:id=&quot;@+id/firstFragment&quot;
          android:name=&quot;com.test.ttt.FirstFragment&quot;
          tools:layout=&quot;@layout/fragment_first&quot;&gt;
  
          &lt;action
              android:id=&quot;@+id/action_firstFragment_to_secondFragment&quot;
              app:destination=&quot;@id/secondFragment&quot;
              app:popUpTo=&quot;@id/firstFragment&quot; 
              app:popUpToInclusive=&quot;true&quot;/&gt;
  
      &lt;/fragment&gt;
  
      &lt;fragment
          android:id=&quot;@+id/secondFragment&quot;
          android:name=&quot;com.test.ttt.SecondFragment&quot;
          tools:layout=&quot;@layout/fragment_second&quot; /&gt;
  
  &lt;/navigation&gt;
  </code></pre>
  <p><strong>FirstFragment.java</strong></p>
  <pre><code>public class FirstFragment extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Navigation.findNavController(container).navigate(FirstFragmentDirections.actionFirstFragmentToSecondFragment());
          return inflater.inflate(R.layout.fragment_first, container, false);
      }
  
  }
  </code></pre>
  <p>I want when I press the back button in the second fragment, It must back to the first fragment but currently, When I press the back button in the second fragment it is leaving the app.</p>
  <p>How can I solve this problem?</p>