title: Bottom Navigation View doesn't work after going to a fragment not inside the bottom navigation view and coming back
body: <p>So my app's architecture is kind of unique, I am using Navigation Components btw.</p>
  <p>It has a main activity that has a NavHostFragment associated with. The NavHostFragment has navigation graph associated with it which has two fragments, Main Fragment (as the start destination) and Settings Fragment (accessible with the menu item in toolbar). <strong>Now the Main Fragments acts as another host for another NavHostFragment.</strong> So here's what that looks like:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.ui.main.fragments.MainFragment&quot;&gt;
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/child_nav_host&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;0dp&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/bottom_navigation_bar&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:navGraph=&quot;@navigation/child_nav_graph&quot; /&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/bottom_navigation_bar&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_nav_menu&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>Note that there's a bottom navigation bar at the bottom of the Main Fragment but there's no such bottom navigation bar in the Main Activity. Also note that the Main Fragment has another NavHostFragment which points to a different Navigation Graph.</p>
  <p>Here's the Main Activity's layout file:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.ui.main.MainActivity&quot;&gt;
  
      &lt;com.google.android.material.appbar.MaterialToolbar
          android:id=&quot;@+id/materialToolbar&quot;
          style=&quot;@style/Widget.MaterialComponents.Toolbar.Primary&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;?actionBarSize&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;/&gt;
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/parent_nav_host&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;0dp&quot;
          app:defaultNavHost=&quot;true&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/materialToolbar&quot;
          app:navGraph=&quot;@navigation/main_nav_graph&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>Here's the main_nav_graph:</p>
  <pre class="lang-xml prettyprint-override"><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/main_nav_graph&quot;
      app:startDestination=&quot;@id/main_fragment&quot;&gt;
      &lt;fragment
          android:id=&quot;@+id/settings_fragment&quot;
          android:name=&quot;com.dbtechprojects.cloudstatustest.ui.main.fragments.SettingsFragment&quot;
          android:label=&quot;Settings&quot;
          tools:layout=&quot;@layout/fragment_settings&quot; /&gt;
      &lt;fragment
          android:id=&quot;@+id/main_fragment&quot;
          android:name=&quot;com.dbtechprojects.cloudstatustest.ui.main.fragments.MainFragment&quot;
          android:label=&quot;Welcome&quot;
          tools:layout=&quot;@layout/fragment_main&quot; /&gt;
  &lt;/navigation&gt;
  </code></pre>
  <p>and here's the child_nav_graph</p>
  <pre class="lang-xml prettyprint-override"><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/main_nav_graph&quot;
      app:startDestination=&quot;@id/aws_fragment&quot;&gt;
  
      &lt;fragment
          android:id=&quot;@+id/aws_fragment&quot;
          android:name=&quot;com.dbtechprojects.cloudstatustest.ui.main.fragments.AwsFragment&quot;
          android:label=&quot;AWS&quot;
          tools:layout=&quot;@layout/fragment_aws&quot; /&gt;
  
      &lt;fragment
          android:id=&quot;@+id/azure_fragment&quot;
          android:name=&quot;com.dbtechprojects.cloudstatustest.ui.main.fragments.AzureFragment&quot;
          android:label=&quot;Azure&quot;
          tools:layout=&quot;@layout/fragment_azure&quot; /&gt;
  
      &lt;fragment
          android:id=&quot;@+id/gcp_fragment&quot;
          android:name=&quot;com.dbtechprojects.cloudstatustest.ui.main.fragments.GcpFragment&quot;
          android:label=&quot;GCP&quot;
          tools:layout=&quot;@layout/fragment_gcp&quot; /&gt;
  &lt;/navigation&gt;
  </code></pre>
  <p>So as you can see, the Main Fragment is what hosts the three other Fragments that are mapped with the Bottom Nav Bar. I am using this approach because I wanted my Settings Fragment to hide the Bottom Nav Bar when I navigate to it. Now the bottom nav bar shows in all the three fragments that I want them to be shown in but not in the settings fragment as I expect it to.</p>
  <p>Now here's the problem, when I open the app, the Main Fragment is shown. The Main Fragment, contains the bottom nav bar when I select one of the items in the bottom nav bar, it correctly navigates to the right fragment. But when I go the settings fragment and then come back, the bottom nav bar stops working. Here's a video showing the behavior: <a href="https://imgur.com/RpQZmhF" rel="nofollow noreferrer">https://imgur.com/RpQZmhF</a></p>
  <p>Here's MainActivity.kt: <a href="https://gist.github.com/ac65ae323ca771d064562d18d9fac880" rel="nofollow noreferrer">https://gist.github.com/ac65ae323ca771d064562d18d9fac880</a>
  Here's the MainFragment.kt: <a href="https://gist.github.com/c700e33b4f04e078abf8c94db9bb6faf" rel="nofollow noreferrer">https://gist.github.com/c700e33b4f04e078abf8c94db9bb6faf</a></p>