3

I have a problem with saving the state of fragments which work with bottom navigation view. I am using the new android jetpack navigation library and it is really simple to code bottom navigation with fragments.

I have 3 fragments in the bottom navigation. When I switch, the fragments are recreated.

OnSaveInstanceState is never called when I just switch between fragments, so it does not work. I tried ViewModel too, it works but I lose the recyclerview position when I switch.

So I just want to simply save the state of fragments with recyclerviews. I don't understand why this simple problem is so difficult to solve. Is there any proper way how to achieve this? I have done a lot of research but I have not found a solution. Thanks.

Simon Featherstone
  • 1,716
  • 23
  • 40
P.Dudik
  • 411
  • 1
  • 5
  • 4
  • Check this (https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711) to achieve what you want, without android navigation components. – Abhimanyu May 30 '19 at 20:06
  • To achieve it using android navigation components, it seems it is not possible as of now as per the comments in this post: https://stackoverflow.com/q/52716962/9636037 – Abhimanyu May 30 '19 at 20:08

0 Answers0