I am using bottom navigation view with navigation components, when previous selected menu item is reselected fragment is reopening from oncreate
When I open my activity document fragment is loading and when I select even fragment and again reselect document fragment he previous state of document fragment is no loading, and document fragment is loading as new fragment.
I want to load previous state of fragment when I again select any of the fragment.
I don't know how to achieve this, any one have any idea about how should I approach this problem?
//my activity.kt
navController = findNavController(R.id.fragmentContainerView)
mViewDataBinding?.bottomNavigation?.setupWithNavController(navController)
//my activity.xml
<fragment
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:navGraph="@navigation/menu_navigation"
app:layout_constraintBottom_toTopOf="@id/bottomNavigation"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
android:background="@color/backgroundColor"
app:itemBackground="@color/backgroundColor"
app:menu="@menu/bottom_navigation_menu"
app:itemIconTint="@color/bottom_nav_item_color"
app:itemTextColor="@color/bottom_nav_item_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
//navigation file
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_navigation"
app:startDestination="@id/documentsFragment">
<fragment
android:id="@+id/documentsFragment"
android:name="packagename.DocumentsFragment"
android:label="DocumentsFragment" />
<fragment
android:id="@+id/eventsFragment"
android:name="packagename.EventsFragment"
android:label="EventsFragment" />
<fragment
android:id="@+id/notesFragment"
android:name="packagename.NotesFragment"
android:label="NotesFragment" />
<fragment
android:id="@+id/tasksFragment"
android:name="packagename.TasksFragment"
android:label="TasksFragment" />
<fragment
android:id="@+id/menuFragment"
android:name="packagename.MenuFragment"
android:label="MenuFragment" />
</navigation>
what I want is to load fragment(state) where the user left previously.