Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@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.
jb...@google.com <jb...@google.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
pr...@google.com <pr...@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.
Description
Version used: 2.8.1
Devices/Android versions reproduced on: many
Your own code:
@Suppress("DEPRECATION")
private fun tryRelaunchUpToExplicitStack(): Boolean {
if (!deepLinkHandled) {
return false
}
val intent = activity!!.intent
val extras = intent.extras
val deepLinkIds = extras!!.getIntArray(KEY_DEEP_LINK_IDS)!!.toMutableList()
val deepLinkArgs = extras.getParcelableArrayList<Bundle>(KEY_DEEP_LINK_ARGS)
// Remove the leaf destination to pop up to one level above it
var leafDestinationId = deepLinkIds.removeLastKt()
deepLinkArgs?.removeLastKt()
// Probably deep linked to a single destination only.
if (deepLinkIds.isEmpty()) {
return false
}
@SinceKotlin("1.4")
public fun <T> MutableList<T>.removeLast(): T = if (isEmpty()) throw NoSuchElementException("List is empty.") else removeAt(lastIndex)
I'm seeing crashes on Crashlytics with that NoSuchElementException, but I'm not being able to reproduce it. Anyways if (deepLinkIds.isEmpty()) cannot be reached because the exception will throw first.