I have 5 item in BottomNavigationBar inside MainActivity class. When open EarningFragment it has FragmentContairView and it open MoneyDetailFragment from EarningFragment. When I opened this MoneyDetailFragment it opened.
In the scenario when click another item on BottomNavigationBar and click again item for EarningFragment it rememeber that was in MoneyDetailFragment and it opened this class. I don't want it is remember where it was. I want it open only EarningFragment when click it in BottomNavigationBar. That's so complicated hope you can understand it.
MainActivity.kt
class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedListener,
View.OnClickListener {
private lateinit var navHostFragment: NavHostFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navHostFragment.navController.addOnDestinationChangedListener(this)
}
private fun setupBottomNavigationView() {
BottomNavigationViewHelper.setupBottomNavigationView(binding.bottomBar.bottomNavViewBar)
binding.bottomBar.bottomNavViewBar.setupWithNavController(navHostFragment.navController)
}
}
nav_graph_main.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_main"
app:startDestination="@id/miHome">
<fragment
android:id="@+id/miHome"
android:name="com.mi.ui.home.HomeFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_to_earningFragment"
app:destination="@id/miEarnings" />
<action
android:id="@+id/action_to_moneyGoldRegisterFragment"
app:destination="@id/moneyGoldRegisterFragment" />
</fragment>
<fragment
android:id="@+id/miEarnings"
android:name="com.mi.ui.earning.EarningFragment"
android:label="@string/menu_bottom_earnings"
tools:layout="@layout/fragment_earning">
<action
android:id="@+id/action_to_moneyCardFragment"
app:destination="@id/moneyCardFragment" />
<action
android:id="@+id/action_to_moneyDetailFragment"
app:destination="@id/moneyDetailFragment" />
</fragment>