I have a Bottom-Navigation in portrait Mode and a Navigation-Rail-View in landscape mode.
How can I update the selected item when the device is rotated?
I tried it with savedInstanceState, with override theonSaveInstanceState and onRestoreInstanceState.
But because I use savedInstanceState for other things too, overide the two above methods cause crash.
Eventually I found a solution.
But before that, I should mention that a better title for this question could be: How to share selection item between the BottomNavigation and NavigationRail.
Ok, solution:
Just replace
setSelectedItemIdwithgetMenu().getItem(itemIndex).setChecked(true)Example:
Use:
Instead of: