So I have a scenario in which I have 5 fragments attached with bottom navigation.
1. Home 2. Inbox 3. Search 4. Notification 5. Profile
So I have another fragment called (BarcodeDetail) to which I navigate from Home Fragment.
(Home -> BarcodeDetail)
Now from BarcodeDetail I navigate to Search Fragment
(BarcodeDetail -> Search)
But now if I select Home Fragment from BottomNavigationView It did not go to Home Fragment.
Rather than it selects the same current fragment that is Search Fragment.
(The log print the name of Search Fragment)
navController.addOnDestinationChangedListener((controller, destination, bundle) -> {
Timber.d("Destination -> %s", destination.getDisplayName());
});
private void setupBottomNavigation() {
NavHostFragment navHostFragment = (NavHostFragment)
getSupportFragmentManager().findFragmentById
(R.id.fragment_container_view);
if (navHostFragment != null) {
navController = navHostFragment
.getNavController();
NavigationUI.setupWithNavController(
binding.bottomNavigation, navController);
initDestinationListener();
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/sellerHomeFragment"
android:icon="@drawable/ic_home"
android:title="@string/home_text" />
<item
android:id="@+id/inboxFragment"
android:icon="@drawable/ic_chat"
android:title="@string/chats_text" />
<item
android:id="@+id/searchFragment"
android:icon="@drawable/ic_search"
android:title="@string/search_text" />
<item
android:id="@+id/sellerAlertFragment"
android:icon="@drawable/ic_notification"
android:title="@string/notifications_text" />
<item
android:id="@+id/sellerProfileFragment"
android:icon="@drawable/ic_profile"
android:title="@string/profile_text" />
</menu>
Please let me know if you need more information. Thanks