8
votes

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.

2
Does this answer your question?Mittal Varsani

2 Answers

1
votes

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

0
votes

There is a problem with Navigation to handle multiple back stacks. A similar solution to this problem is available here

You can also use ViewModels to preserve the view state.