Status Update
Comments
il...@google.com <il...@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.
Description
Component used: Fragment Version used: 1.3.3 Devices/Android versions reproduced on: Broad spectrum of devices (from Samsung, Google, LGE, TCL, Archos, and Motorola) and Android versions (6.0.1, 8.0.0, 8.1.0, 9, 10, 11)
I have not been able to reproduce this crash, so I can't attach a project in which it can be reproduced, nor screenshots. All I have to go on so far are stack traces.
For example, in this stack trace, our app has received an Intent which includes a deeplink. To handle this, we attempt to close an open Fragment before creating the new one, hence the call to popBackStackImmediate():
I'm reluctant to just catch the
NullPointerException
, as I can see inpopBackStackImmediate(@Nullable String name, int id, int flags)
that we would be proceeding without these methods having been invoked, and I worry we would be in a bad state in terms of Fragment management:We are using:
androidx.fragment:fragment:1.3.3
androidx.fragment:fragment-ktx:1.3.3