Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit b17204359581a71c427d7519a6cfc1825141ed72
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Mar 17 21:47:24 2023
Prevent crash when adding unmanaged fragment in nav
Currently, if you attempt to add a fragment to the fragment manager
associated with the FragmentNavigator, navigation crashes as it cannot
find an entry associated with fragment.
While it is strongly recommended to only use navigation APIs to
manipulate the fragment manager, if the back stack is not affected, then
we should not crash.
RelNote: "Adding fragments to the `FragmentNavigator`'s
`FragmentManager` without using navigation will no longer crash."
Test: Added FragmentNavigatorTest
Bug: 274167493
Change-Id: I47d4c75ca46ee7f8282b2a7b97d28d71edd9a07b
M navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/FragmentNavigatorTest.kt
M navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/FragmentNavigator.kt
https://android-review.googlesource.com/2496343
Branch: androidx-main
commit b17204359581a71c427d7519a6cfc1825141ed72
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Mar 17 21:47:24 2023
Prevent crash when adding unmanaged fragment in nav
Currently, if you attempt to add a fragment to the fragment manager
associated with the FragmentNavigator, navigation crashes as it cannot
find an entry associated with fragment.
While it is strongly recommended to only use navigation APIs to
manipulate the fragment manager, if the back stack is not affected, then
we should not crash.
RelNote: "Adding fragments to the `FragmentNavigator`'s
`FragmentManager` without using navigation will no longer crash."
Test: Added FragmentNavigatorTest
Bug: 274167493
Change-Id: I47d4c75ca46ee7f8282b2a7b97d28d71edd9a07b
M navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/FragmentNavigatorTest.kt
M navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/FragmentNavigator.kt
il...@google.com <il...@google.com> #3
This has been fixed internally and will be in the Navigation 2.6.0-alpha08
release.
Description
Version used:android.arch.navigation:navigation-ui:1.0.0-beta01
Devices/Android versions reproduced on: any
Navigation to a fragment destination with SingleTop option breaks back stack. The issue was introduced in beta01 update in commit 45818ac652ba3a43b07f980cf22ab78be886d81d by Ian Lake <ilake@google.com> on Wed Jan 30 10:45:37 2019 -0800.
I believe that the root of the issue is unnecessary "+ 1" in line 25 of androidx.navigation.fragment.FragmentNavigator.java:
ft.addToBackStack(generateBackStackName(mBackStack.size() + 1, destId));
When navigation is performed in SingleTop mode, the last fragment is being replaced making back stack 1 frame smaller.