I've been searching on this topic for a while now, without any success. Since the last update of Navigation Component 2.5.0 in combination with BottomNavigationView the nav controller retain the stack state for each tab of BottomNavView.
Now, I am asking if there is any way to exclude a graph or some fragments from this rule ?
More in details:
- I have 1
activityand the rest arefragments - I have
BottomNavigationViewwith 4 tabs - it is setup with nav controller
- each tab starts a separate
graph(no confusions) - seems clean, especially in a bigger application - besides this, I have 2 icons on the toolbar (let's say
helpandsettings) - these two icons, are Global Actions because are started from activity, not from a fragment, and can be accessed from almost any point
Why do I want to exclude some fragments (help and settings) from this rule to retain their state? Well, because navigating to one of them and then changing the BottomNavigationView tabs back and forth, I can end up having these fragments over all of my 4 tabs (or those 4 main graphs)
What I have tried?
- A tricky solution to add
settingsandfaqinto theBottomNavigationViewbut without being visible, and just link the global action to that tab (manually setting the current item of theBottomNavView) - failed, because I've ended up with 6 items in theBNVand it will cause a crash, as more than 5 items is a design concern. - I tried using two controllers for this activity, 1 to be linked with
BNVand the other to take care of the global actions, of course I ended up with a bit of a mess.
Maybe I am asking too much from Android, but I would like to be able to keep this default behaviour added in 2.5.0 for Navigation but at the same time write some exceptions from it. I wouldn't mind manually handling the navigations for each BNV tabs, but my issue is with the global actions.
Any suggestions would be highly appreciated.