Fixed
Status Update
Comments
da...@sucharda.cz <da...@sucharda.cz> #2
Yes, this is correct. Having individual navigation graphs on each activities overrides or disallow up navigation to the main activity.
jb...@google.com <jb...@google.com> #3
I believe I have found the potential problem that is causing this:
// @ androidx.navigation.NavController
// line 124
// Now record the pop operation that we were sent
if (!mBackStack.isEmpty()) {
mBackStack.removeLast();
}
// We never want to leave NavGraphs on the top of the stack
while (!mBackStack.isEmpty()
&& mBackStack.peekLast() instanceof NavGraph) {
popBackStack();
}
the condition in while loop is never satisfied because of the above `if` statement above it has already removed the last item of the mBackStack (which was the NavGraph) and thus popBackStack() is never called again.
// @ androidx.navigation.NavController
// line 124
// Now record the pop operation that we were sent
if (!mBackStack.isEmpty()) {
mBackStack.removeLast();
}
// We never want to leave NavGraphs on the top of the stack
while (!mBackStack.isEmpty()
&& mBackStack.peekLast() instanceof NavGraph) {
popBackStack();
}
the condition in while loop is never satisfied because of the above `if` statement above it has already removed the last item of the mBackStack (which was the NavGraph) and thus popBackStack() is never called again.
da...@sucharda.cz <da...@sucharda.cz> #4
According to Ian Lake, NavigationUI does not support up navigation yet, that is why this is a feature request.
+Pedro Varela - we don't support navigating up through activities as part of NavigationUI yet, please star the feature request:https://issuetracker.google.com/issues/79993862 (this issue)
+Pedro Varela - we don't support navigating up through activities as part of NavigationUI yet, please star the feature request:
da...@sucharda.cz <da...@sucharda.cz> #5
Ian Lake said Up navigation is not supported through activities, only through fragments.
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com> #6
With the introduction of AppBarConfiguration, this is now possible with the setupActionBarWithNavController method by using an empty set of top level destinations (to always show the up button) and then overriding onSupportNavigateUp() as per the documentation: https://developer.android.com/topic/libraries/architecture/navigation/navigation-ui#action_bar
I'll leave this bug open as we still need an equivalent API for the Toolbar versions.
I'll leave this bug open as we still need an equivalent API for the Toolbar versions.
ap...@google.com <ap...@google.com> #7
This allows you to call onSupportNavigateUp() (or super.onSupportNavigateUp() if you're using an ActionBar) from that method to have your Up button transition between activities.
This will be available in 1.0.0-alpha09.
pr...@google.com <pr...@google.com> #8
There is Jarks when implementing this way to navigate up between activities.
Description
Component used: Navigation
Version used: 2.5.1 and 2.5.2
Last known working version: 2.3.5
Devices/Android versions reproduced on: Huawei P20 Light / AN 9 (EMUI 9.1.0)
So our navigation is kinda complex so I will try to simplify the configuration. If there is a nested graph with arguments which cannot be null (and no default value is supplied) and
popUpTo
is used to remove nested graph during destination (nested) navigation it tries to recreate nested graph as a parent for the destination being navigated to.So now if the navigation is triggered like this:
It will pop fragments from back stack, but it will not change parent for
ChildFragment2
which will be set tochildNavGraph
and since it is not in the back stack anymore it will try to recreate it with default values. ButargumentLong
is not nullable and has no default value so it will crash:Note: Interesting thing is that it does not crash with non-nullable String argument for some reason (ah I see, it is because String NavType is nullable by default:
StringType: NavType<String?>
vsLongType: NavType<Long>
).Possible fixes for us:
popUpTo
to pop parent (navGraph) of a Fragment (node) from XML but usepopBackStack
from code instead.argumentLong
.Basically I am not sure if this an intended behavior or a bug. Gonna mark it as a bug because it worked in 2.3.5. I understand that Destination should have a parent but what is the reason to create a parent that does not exist and will never be displayed in this case, since it was already poped and thus it should not be displayed to the user.
At the moment two solutions come to mind:
LongType
and other types nullable same asStringType
. Again not sure if this can be done and it probably is not a proper solution (change).There might of course be other solutions that I cannot see.
Thank you for your time and help.