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

[NavigationCodelab] Arguments retrieved by navBackStackEntry #302

Open
jlgconde opened this issue Nov 3, 2022 · 2 comments
Open

[NavigationCodelab] Arguments retrieved by navBackStackEntry #302

jlgconde opened this issue Nov 3, 2022 · 2 comments
Assignees

Comments

@jlgconde
Copy link

jlgconde commented Nov 3, 2022

Hi, the accountType retrieved by the navBackStackEntry in the Rally app of the Navigation Codelab only works the first time. Afterwards, no matter which account I click, it goes to the single account I clicked the first time. The accountType value doesn't change :( Any help would be welcomed.

@jlgconde jlgconde changed the title Arguments retrieved by navBackStackEntry [NavigationCodelab] Arguments retrieved by navBackStackEntry Nov 3, 2022
@jlgconde
Copy link
Author

jlgconde commented Nov 3, 2022

Hi, I've commented the restoreState = true line that is part of the solution and the app works properly now. I would like to understand what's happening and why, if this is just a mistake in the codelab and if so what's the proposed solution. Thanks in advance for any support!

@tomashugo
Copy link

Hi, I've commented the restoreState = true line that is part of the solution and the app works properly now. I would like to understand what's happening and why, if this is just a mistake in the codelab and if so what's the proposed solution. Thanks in advance for any support!

The bug happens because NavHost isn't able to treat the routes "accounts/Checking", "accounts/Home Savings", etc. as different routes, and it is restoring the state of the route ignoring the argument.

The best solution for this is set inclusive parameter to true inside the popUpTo call. This way NavHost will see the argument of your route too.

popUpTo(this@navigateSingleTopTo.graph.findStartDestination().id) {
               saveState = true
               inclusive = true
}

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

4 participants
@tomashugo @simona-anomis @jlgconde and others