0

The navigation from menus is working fine, but when I added the FAB and tried to use in navigation component it crashed.

Here is the xml of my bottomAppBar:

Here is the xml of my bottomAppBar

My question is how would I able to use navigation component for the Items (Favourites, IDD Voice)?.

I used this.

favouritesFab.setOnClickListener {
        navController.navigate(R.id.action_homeFragment_to_balanceAndRechargeFragment)
    }

It's working if i'm only in the "Home", then if I navigate to a different menu it will crashed, also if I am in different menu ex:("Usage" or "Accounts") and tried to clicked the "Favourites" it will also crashed and the result will be this.

java.lang.IllegalArgumentException: Navigation action/destination org.multisys.dst.stg:id/action_homeFragment_to_balanceAndRechargeFragment cannot be found from the current destination Destination(org.multisys.dst.stg:id/linkedAccountListsFragment) label=linked_accounts_list_fragment class=org.multisys.dst.ui.linkedaccounts.ui.LinkedAccountListsFragment

How can I use the items in the FAB to navigate like the menus using navigation component?

Thank you.

Cyd
  • 1,245
  • 1
  • 14
  • 17

1 Answers1

0

It is crashing because the action you are using is R.id.action_homeFragment_to_balanceAndRechargeFragment and when you try to navigate from any Fragment other than homeFragment, it will crash as currentDestination will be different like ("Usage" or "Accounts").

So it can be solved by

favouritesFab.setOnClickListener {
    navController.navigate(R.id.balanceAndRechargeFragment)
}