0

I'm using BottomNavigationView to navigate between two Fragments, on of these fragments has its own ViewPager with TabLayout as below:

enter image description here

This is what i'm trying to do:

MainActivity
 |--- HomeFragment
 |           |--- POPULAR
 |           |--- LATEST
 |           |--- TOP RATED
 |           |--- UPCOMING
 |--- FavoritesFragment

it works fine while swiping the ViewPager, the problem occures when i'm in LATEST or TOP RATED and navigates the BottomNavigationView to FavoritesFragment and return back to HomeFragment, the ViewPager starts over from POPULAR not the fragment i was in before navigation.

How can i avoid this tricky navigation problem?

And what is the best solution to keep track of navigation in such situation?

iosamammohamed
  • 317
  • 3
  • 18

1 Answers1

0

addToBackStack

Fragment Transactions

And what is the best solution to keep track of navigation in such situation?

I am obviously unaware of a best solution. A case like this involves fragment lifecycles as well which further complicate things. If you want a very specific navigation behaviour - specially the ability to resume from any previous UI state - I would suggest using a log file to keep track of lifecycle and navigation changes. This has often paid off for me in the long run

Kelsnare
  • 635
  • 5
  • 12