Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.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
sl...@czerwinski.info.pl <sl...@czerwinski.info.pl> #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.
il...@google.com <il...@google.com>
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.
il...@google.com <il...@google.com> #6
It would be interesting to have a "popAll" option, where the whole stack will be erased, so we don't have to keep track who's on the stack to be popped or not. It would speed up things and bring less confusion as well.
ap...@google.com <ap...@google.com> #7
I agree completely, similarly to how clearTask worked before it was deprecated.
Description
Version used: 1.0.0-alpha02
Devices/Android versions reproduced on: Emulator API 28, Samsung J5 API 25
Sample project attached.
I'm trying to create a custom Navigator and custom NavDestination that would animate ConstraintLayout (but any custom NavDestination would cause this issue).
Intended behaviour is shown in attached video: Layout_animations.webm
However, when I rotate the screen, while the navigation is on the custom destination, the application crashes.
The crash is caused by an unknown destination, which can only be added after custom navigator.
If I add custom destination in nav_main.xml, the app will also crash, because the navigator is not yet added.
This issue could be fixed by extending NavHostFragment, but I would need to override the whole onCreate() method.
I would need to add my custom navigator right after the line:
mNavController = new NavController(context);
I can think of 2 possible solutions in the library:
1. Delegate creating of NavController, so that a custom NavController can be provided in the XML layout file.
2. Call a new protected method "NavHostFragment.onNavControllerCreated(NavController)" right after the NavController is created, that could be overridden in a custom NavHostFragment, before the graph is created.
If there is any solution to my problem that I didn't think of, please provide a more exhaustive example in the documentation:
Stack trace:
2018-06-25 10:54:28.356 14543-14543/it.czerwinski.customnavigatorexample E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.czerwinski.customnavigatorexample, PID: 14543
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.czerwinski.customnavigatorexample/it.czerwinski.customnavigatorexample.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4792)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4711)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
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:826)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
Caused by: java.lang.IllegalStateException: unknown destination during restore: it.czerwinski.customnavigatorexample:id/animatedLayoutDestination
at androidx.navigation.NavController.onGraphCreated(NavController.java:424)
at androidx.navigation.NavController.setGraph(NavController.java:386)
at androidx.navigation.NavController.restoreState(NavController.java:742)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:215)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2400)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1684)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3772)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:395)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:377)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:467)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at it.czerwinski.customnavigatorexample.MainActivity.onCreate(MainActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:7130)
at android.app.Activity.performCreate(Activity.java:7121)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4792)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4711)
2018-06-25 10:54:28.356 14543-14543/it.czerwinski.customnavigatorexample E/AndroidRuntime: at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
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:826)