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.
zb...@gmail.com <zb...@gmail.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
il...@google.com <il...@google.com> #4
Thank you for promptly replying to my report. You are right that the issue you've just mentioned is similar to mine. I shall continue observing the progress over there.
zb...@gmail.com <zb...@gmail.com> #5
Thanks for the response, I will check it out :)
zb...@gmail.com <zb...@gmail.com> #6
Hmm, I have modified the navigation code lab example to include action popping up to root with popUpToInclusive="true", but it still doesn't seem to work.
Am I missing something?
https://github.com/googlecodelabs/android-navigation/compare/master...zbigniew-malinowski:clear_stack_problem
To reproduce: click "Navigate with action" button on the "Home" screen, and then press back
Expected result: exits the app.
Actual result: pops back to "Home" screen
Am I missing something?
To reproduce: click "Navigate with action" button on the "Home" screen, and then press back
Expected result: exits the app.
Actual result: pops back to "Home" screen
il...@google.com <il...@google.com> #7
zb...@gmail.com <zb...@gmail.com> #8
Will do, thanks!
Description
Version used: 1.0.0-alpha02
Devices/Android versions reproduced on: Emulator API 27
Expected result:
When executing a navigation action with Clear Task flag set (either in the editor or in NavOptions) with an activity as a target, the target activity becomes the root (and the sole activity) of the current task and pressing back button shouldn't allow comming back to the source activity.
Before: [A]
Action: A -> B
After: [B]
Actual result:
The target activity is just added to the back stack, so popping navigates back to the source activity.
Before: [A]
Action: A -> B
After: [A, B]
I think this is caused by setting only Intent.FLAG_ACTIVITY_CLEAR_TASK, without Intent.FLAG_ACTIVITY_NEW_TASK.
ActivityNavigator, lines 117-119:
if (navOptions != null && navOptions.shouldClearTask()) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
According to the docs:
"If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK."