Hidden fragment dont loose the state but when hiding fragment on onSaveInstanceState the state lost, why?

88 views Asked by At

My application has a ‍‍‍‍BottomNavigation with 4 tabs, I had a fragment for every tab and add all of this 4 fragment to FragmentManager. When one of this tab is selected, I hide other fragment and show the fragment of this tab.
My problem is, when the screen is rotated, hidden fragments don't lose the state, and showing tab loose the state.
I try to hide the showing fragment in onSaveInstanceState and show it in onCreateView but it didn't work!
Why the hidden fragment saves their own state but showing fragment lost it? And how I can use this feature to save state of showing fragment?

My application using nested fragments, I have 4 main fragment and showing another page in that fragment I replace it with other fragment and save replaced fragment to backstack of childFragmentManager for saving backstack of every tab.
When I rotate the screen, only showing tab going back to first fragment like first time this tab is show, but other tabs saving their stats! I want to save the state of showing fragment like others, how can I do it?

0

There are 0 answers