Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating bug (Destination does not exist in nav controller) #11

Closed
mitchtabian opened this issue Mar 9, 2020 · 1 comment
Closed
Assignees

Comments

@mitchtabian
Copy link
Owner

Starting at version nav components versions 2.1.0-alpha03 my code will crash the app by doing the following:

  1. Nav to BlogFragment
  2. Press back
  3. Nav to BlogFragment

The problem seems to be the childFragmentManager. If you pop from there it removes the graph along with the last fragment, which causes the "Destination not part of this NavGraph" exception when you then try to navigate forward again.

@mitchtabian mitchtabian self-assigned this Mar 9, 2020
@mitchtabian
Copy link
Owner Author

mitchtabian commented Mar 9, 2020

Solution branch: https://github.com/mitchtabian/Open-API-Android-App/tree/navigation-bug

Notes:

Just replace the OnBackPressed function in BottomNavController.

Simply getting a reference to the NavController

val navController = fragmentManager.findFragmentById(containerId)!!
            .findNavController()

Then popping if backstack size > 2 (One for start destination and one for the NavGraph)

navController.backStack.size > 2{
    navController.popBackStack()
}

Here are all the changes: https://gist.github.com/mitchtabian/3d4e58e56a5f07d9ff582f6c275f58a0

The only reason I can think of that would cause this is I was using the childFragmentManager incorrectly. I suppose you should only use childFM if you set a FragmentFactory to generate the fragments from? Like I did in Espresso course. Not 100% sure.

Tested up to version 2.3.0-alpha03.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant