title: Return the state of navigation controller (Android Navigation Component)
body: <p>I'm using button navigation and NavController. All my fragments in same navigation container. When I switch between tabs I want to store travel stack, that allow to return on current tab state. I try to use NavController.saveState() and after restoreState(). But after calling this function nothing changed. How I can achieve this?</p>
  
  <pre><code>val bottomNavigationListener = object :
      BottomNavigationView.OnNavigationItemSelectedListener {
      override fun onNavigationItemSelected(item: MenuItem): Boolean {
          when (item.itemId) {
              R.id.menu_statistic -&gt; handleTabClick(item.itemId, R.id.statisticsFragment)
              R.id.menu_tracker -&gt; handleTabClick(item.itemId, R.id.trackerFragment)
              R.id.menu_wiki -&gt; handleTabClick(item.itemId, R.id.wikiFragment)
              else -&gt; return false
          }
  
          return true
      }
  }
  
  
  
  private fun handleTabClick(tabId: Int, hostFragmentId: Int) {
      if(currentTabId != tabId) {
          if(navController.currentDestination?.id != hostFragmentId) {
              destinationsHistory[currentTabId] = navController.saveState() ?: Bundle()
          } else {
              destinationsHistory[currentTabId] = Bundle()
          }
  
          val bundle = destinationsHistory[tabId] ?: Bundle()
  
          if(!bundle.isEmpty) {
              navController.restoreState(bundle)
          } else {
              navController.navigate(hostFragmentId)
          }
      } else {
          destinationsHistory[tabId] = Bundle()
          if (navController.currentDestination?.id != hostFragmentId) {
              navController.navigate(hostFragmentId)
          }
      }
  
      currentTabId = tabId
  }
  
  
  &lt;navigation xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_graph"
          app:startDestination="@id/wikiFragment"&gt;
  
  &lt;fragment android:id="@+id/statisticsFragment" android:name="com.sc.overhub.view.fragment.StatisticsFragment"
            android:label="StatisticsFragment"/&gt;
  &lt;fragment android:id="@+id/trackerFragment" android:name="com.sc.overhub.view.fragment.TrackerFragment"
            android:label="TrackerFragment"/&gt;
  
  &lt;fragment android:id="@+id/wikiFragment" android:name="com.sc.overhub.view.fragment.wiki.WikiFragment"
            android:label="fragment_wiki" tools:layout="@layout/fragment_wiki"&gt;
      &lt;action android:id="@+id/action_wikiFragment_to_wikiHeroesListFragment"
              app:destination="@id/wikiHeroesListFragment"/&gt;
      &lt;action android:id="@+id/action_wikiFragment_to_mapsFragment" app:destination="@id/mapsFragment"/&gt;
  &lt;/fragment&gt;
  &lt;fragment android:id="@+id/wikiHeroesListFragment"
            android:name="com.sc.overhub.view.fragment.wiki.herosList.WikiHeroesListFragment"
            android:label="WikiHeroesListFragment"&gt;
      &lt;action android:id="@+id/action_wikiHeroesListFragment_to_wikiHeroFragment"
              app:destination="@id/wikiHeroFragment"/&gt;
  &lt;/fragment&gt;
  &lt;fragment android:id="@+id/wikiHeroFragment"
            android:name="com.sc.overhub.view.fragment.wiki.herosList.hero.WikiHeroFragment"
            android:label="fragment_view_hero" tools:layout="@layout/fragment_wiki_hero"/&gt;
  &lt;fragment android:id="@+id/mapsFragment" android:name="com.sc.overhub.view.fragment.wiki.maps.MapsFragment"
            android:label="MapsFragment"/&gt;
  </code></pre>
  
  <p></p>