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.
ba...@gmail.com <ba...@gmail.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
Description
Version used: 1.0.0
Devices/Android versions reproduced on: Google Pixel 2XL
I am developing an app by making use of Navigation Architecture Component and I am running into a strange behavior with at least one of the navigation actions I have defined(at least only one has caught my eye yet).
<action
android:id="@+id/action_loginFragment_to_dashboardFragment"
app:destination="@id/dashboardFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_in_right"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
When this action is executed, it causes a brief recreate and destruction of LandingPageFragment which comes before LoginFragment.
Below I can paste a log that might make it easier to understand what issue I am facing.
The app went through a cold start when the log was produced and I went from A >> B >> C
2019-04-04 14:36:04.103 13457-13457/
2019-04-04 14:36:06.535 13457-13457/
2019-04-04 14:36:06.634 13457-13457/
2019-04-04 14:36:13.676 13457-13457/
2019-04-04 14:36:13.715 13457-13457/
2019-04-04 14:36:13.729 13457-13457/
2019-04-04 14:36:13.866 13457-13457/
the 5th and 7th lines of the logs reflect the anomaly. There is no UI glitch at all, but nonetheless, this is not an intended behavior I would assume and can lead to potential crashes in applications.