What is the best practice to highlight the right menu item in a BottomNavigationView after coming back to that Activity?
My Scenario: a MainActivity with a bottomNavigation which switches between fragments and starts other Activities. The Activities started from that menu have android:parentActivityName=".activities.MainActivity"
set in the manifest file. A click on the back button in the top bar brings me back to the right Activity and the last visited Fragment in this Activity is shown too, since I have added android:launchMode="singleTop"
for the MainActivity. BUT always the first menu item is highlighted
My workaround at the moment is to add the following code to every Fragment (not very nice)
@Override
public void onResume() {
super.onResume();
BottomNavigationView navigation = (BottomNavigationView) getActivity().findViewById(R.id.navigation);
Menu menu = navigation.getMenu();
for (int i = 0; i < menu.size() ; i++) {
menu.getItem(i).setChecked(false);
}
menu.getItem(MENU_ITEM_POS).setChecked(true);
}