Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragments are always recreated when used with Android navigation from jetpack

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.

like image 378
Varun A M Avatar asked Apr 29 '20 06:04

Varun A M


People also ask

What is android navigation component?

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.

What is popUpToInclusive?

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 .

What is Nav_host_fragment?

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.


1 Answers

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

like image 199
SURYA N Avatar answered Oct 24 '22 10:10

SURYA N