Status Update
Comments
jb...@google.com <jb...@google.com> #2
This actually has nothing to do with NavHostFragment, but is the behavior of NavController's setGraph().
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
tp...@gmail.com <tp...@gmail.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
Description
Component used: Navigation, Navigation-safe-args-gradle-plugin
Version used: 2.6.0-rc01
Devices/Android versions reproduced on: All
If this is a bug in the library, we would appreciate if you could attach:
When the project has conditional navigation setup programmatically, navigating by action generated by safeargs plugin will result in the app crashes with the following error after a back is performed.
Issue does not occur when navigating by resId or when back is performed by popBackStack.
Steps to reproduce
Note that if clicking on "Popback Simple details Fragment" to pop back or clicking on the "Open Simple details Fragment by resId" to navigate by resId, the app doesn't crash when navigating to SimpleDetailsFragment