15

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Varun A M
  • 1,103
  • 2
  • 14
  • 29

3 Answers3

4

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

SURYA N
  • 299
  • 2
  • 16
0

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.

kaustubhpatange
  • 442
  • 5
  • 13
0

As alternative you can use hide/show fragment instead of navigation: Show hide fragment in android

Glebka
  • 1,420
  • 3
  • 20
  • 37