Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ma...@gmail.com <ma...@gmail.com> #2
I'm still having the same issues in:
Android Studio 3.3 Canary 12
Build #AI-182.4505.22.33.5026711, built on September 24, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Android Studio 3.3 Canary 12
Build #AI-182.4505.22.33.5026711, built on September 24, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
ch...@moqi.co.uk <ch...@moqi.co.uk> #3
Any updates on this? Have you been able to reproduce it? It's a release blocker on our end — any resonable workaround would be appreciated.
il...@google.com <il...@google.com> #4
I think I have an idea of what is going on. Do you see a Log.INFO message saying: "Ignoring popBackStack to destination __ as it was not found on the current back stack"? If so, that means we're doing exactly what you said - popping id/graph off the stack - but not actually what you want (the parent graph to continue to be around if you are navigating forward as well)
If so, one workaround is to use popUpTo="@+id/a" and popUpTo"@+id/b" for action x and y, respectively - if you know that x is always clearing A off the stack, then popUpTo B is enough.
If so, one workaround is to use popUpTo="@+id/a" and popUpTo"@+id/b" for action x and y, respectively - if you know that x is always clearing A off the stack, then popUpTo B is enough.
ap...@google.com <ap...@google.com> #5
Alright, interesting! So that means there is no generic way to say that "clear everything of the backstack before moving to this next destination"? Rather, you need to keep track of every individual case? What if, for example, you have to following graph:
x y z
A --> B --> C --> D
Where
- A could be a splash screen and the start destination of the graph
- B could be some welcome screen, prompting the user to sign in
- C could be the actual login screen where the user enters his/hers details and signs in
- D could be the main content screen
Obviously the user should not be allowed to click the back button from B to go back to the splash screen, and neither should the user be allowed to click the back button from D to go back to the login screen. In both of these cases the user should instead exit the app. However, it's perfectly fine for the user to click back from C and go back to the welcome screen B.
Now, to the problem; with your suggested workaround we can indeed set popUpTo="@+id/a" on x, but if we set popUpTo="@+id/c" on z then the user can still click the back button, but they will go to B instead. The desired behaviour is for the user to exit the app when clicking back when in D. The workaround stops working as we don't pop the back stack when going from B --> C, as we want to allow the user to navigate back to B from C.
x y z
A --> B --> C --> D
Where
- A could be a splash screen and the start destination of the graph
- B could be some welcome screen, prompting the user to sign in
- C could be the actual login screen where the user enters his/hers details and signs in
- D could be the main content screen
Obviously the user should not be allowed to click the back button from B to go back to the splash screen, and neither should the user be allowed to click the back button from D to go back to the login screen. In both of these cases the user should instead exit the app. However, it's perfectly fine for the user to click back from C and go back to the welcome screen B.
Now, to the problem; with your suggested workaround we can indeed set popUpTo="@+id/a" on x, but if we set popUpTo="@+id/c" on z then the user can still click the back button, but they will go to B instead. The desired behaviour is for the user to exit the app when clicking back when in D. The workaround stops working as we don't pop the back stack when going from B --> C, as we want to allow the user to navigate back to B from C.
Description
android.arch.navigation:navigation-fragment-ktx
android.arch.navigation:navigation-ui-ktx
Version used:
1.0.0-alpha05
Devices/Android versions reproduced on:
-SM-A510F, Android 7.0
-Emulator x86_64 API 28
Sample project:
Description:
Having this structure:
nav_graph.xml
<navigation
android:id="@+id/nav_graph"
app:startDestination="@id/startFragment">
<fragment
android:id="@+id/startFragment"
android:name="com.example.navbug.StartFragment"
android:label="StartFragment"
tools:layout="@layout/fragment_start">
<action
android:id="@+id/action_startFragment_to_nested_nav_graph"
app:destination="@id/nested_nav_graph" />
</fragment>
<include app:graph="@navigation/nested_nav_graph" />
</navigation>
nested_nav_graph.xml
<navigation
android:id="@+id/nested_nav_graph"
app:startDestination="@id/nestedStartFragment">
<fragment
android:id="@+id/nestedStartFragment"
android:name="com.example.navbug.NestedStartFragment"
android:label="NestedStartFragment">
<action
android:id="@+id/action_nestedStartFragment_to_nestedSecondFragment"
app:destination="@id/nestedSecondFragment"
app:popUpTo="@+id/nestedStartFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/nestedSecondFragment"
android:name="com.example.navbug.NestedSecondFragment"
android:label="NestedSecondFragment" />
</navigation>
I want to achieve this navigation pattern:
StartFragment => NestedStartFragment => NestedSecondFragment =(back)=> StartFragment
I'm trying to implement this by setting the action NestedStartFragment=>NestedSecondFragment with the options [popUpTo=NestedStartFragment, popUpToInclusive=true], so that the resulting stack would be:
0. NestedSecondFragment
1. NestedNavGraph
2. StartFragment
3. NavGraph
When navigating from NestedStartFragment to NestedSecondFragment, the following execption occurs:
java.lang.IllegalArgumentException: Navigator androidx.navigation.fragment.FragmentNavigator@ccc9092 reported navigation to unknown destination id com.example.navbug:id/nestedSecondFragment
at androidx.navigation.NavController$2.onNavigatorNavigated(NavController.java:142)
at androidx.navigation.Navigator.dispatchOnNavigatorNavigated(Navigator.java:217)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:207)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:45)
at androidx.navigation.NavDestination.navigate(NavDestination.java:407)
at androidx.navigation.NavController.navigate(NavController.java:683)
at androidx.navigation.NavController.navigate(NavController.java:630)
at androidx.navigation.NavController.navigate(NavController.java:618)
at com.example.navbug.NestedStartFragment$onViewCreated$1.onClick(Fragments.kt:31)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Right before the navigation, the stack is:
0. NestedStartFragment
1. NestedNavGraph
2. StartFragment
3. NavGraph
When NestedStartFragment is popped on my request, NestedNavGraph is also popped because
"// We never want to leave NavGraphs on the top of the stack" (from NavController.onNavigatorNavigated)
with the effect that eventually the requested destination NestedSecondFragment is pruned from the graph and cannot be reached anymore.
Unless I'm doing something wrong, it seems that NavGraph automatic popping should be avoided if the final destination actually belongs to it.