I am facing this issue of fragments recreation with Android navigation component. I have integrated bottom navigation and coupled it with the android navigation component. So, every time I click on a tab on bottom bar, the fragment is recreated and the old state is not persisted.
I want to retain the state of fragment even when I go to other tabs and come back. I am not finding any solution for it anywhere.
Except bottom navigation, I am using navController.navigate()
method to navigate between different fragments.
Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. The Navigation component also ensures a consistent and predictable user experience by adhering to an established set of principles.
app:popUpToInclusive="true"/> </fragment> </navigation> When the navigation graph is inflated, these actions are parsed, and corresponding NavAction objects are generated with the configurations defined in the graph. For example, action_b_to_a is defined as navigating from destination b to destination a .
NavHostFragment provides an area within your layout for self-contained navigation to occur. NavHostFragment is intended to be used as the content area within a layout resource defining your app's chrome around it, e.g.: <androidx.drawerlayout.widget.DrawerLayout.
Hi the problem is fixed in latest version 2.4.0-alpha01 now there is a support multiple backstack navigation
Checkout the link: https://developer.android.com/jetpack/androidx/releases/navigation#version_240_2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With