Bug P3
Status Update
Comments
jb...@google.com <jb...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 85c1de7395f07e3256a50706d4f619e654624250
Author: Ian Lake <ilake@google.com>
Date: Fri Apr 19 13:54:21 2019
Ensure Fragment OnBackPressedCallbacks take priority
As FragmentController is not yet driven by a
LifecycleObserver ( b/127528777 ), LifecycleObservers on
Fragments are not necessarily nested within
LifecycleObservers registered at the Activity level.
This can lead to cases where a Fragment is started
before the Activity's Lifecycle is started.
In the case of FragmentManager's usage of Lifecycle to
add OnBackPressedCallbacks, that nesting is critical
to ensure the ordering of callbacks. By creating a
host level Lifecycle that is exactly nested outside
the callbacks to FragmentController, we can ensure
the proper nesting in callbacks.
Test: added test passes
Change-Id: I958d2389c90dcd9d157c6c3d30dffb689ed40c62
M fragment/src/androidTest/AndroidManifest.xml
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
https://android-review.googlesource.com/948209
https://goto.google.com/android-sha1/85c1de7395f07e3256a50706d4f619e654624250
Branch: androidx-master-dev
commit 85c1de7395f07e3256a50706d4f619e654624250
Author: Ian Lake <ilake@google.com>
Date: Fri Apr 19 13:54:21 2019
Ensure Fragment OnBackPressedCallbacks take priority
As FragmentController is not yet driven by a
LifecycleObserver (
Fragments are not necessarily nested within
LifecycleObservers registered at the Activity level.
This can lead to cases where a Fragment is started
before the Activity's Lifecycle is started.
In the case of FragmentManager's usage of Lifecycle to
add OnBackPressedCallbacks, that nesting is critical
to ensure the ordering of callbacks. By creating a
host level Lifecycle that is exactly nested outside
the callbacks to FragmentController, we can ensure
the proper nesting in callbacks.
Test: added test passes
Change-Id: I958d2389c90dcd9d157c6c3d30dffb689ed40c62
M fragment/src/androidTest/AndroidManifest.xml
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
la...@gmail.com <la...@gmail.com> #3
FWIW, I think this is a fantastic idea and would go a long way in bringing sanity to the world of lifecycle. As it would change the ordering between Activity lifecycle methods and Fragment lifecycle methods, this will almost certainly be an opt-in flag set at the FragmentActivity level.
hy...@gmail.com <hy...@gmail.com> #4
It's worth noting, that I actually expected the Activity to fire Lifecycle.Event.ON_CREATE from `Activity.onCreate` which is what the fragmentLifecycleRegistry does.
Not sure how this would be exposed, but driving Activity.getLifecycle events from the ReportFragment which is actually a different lifecycle to that Activity is very odd.
Not sure on the API, but a getActivityLifecycle and getFragmentLifecycle would be nice in this situation, as I actually want my lifecycle events to fire IN onCreate not in onStart.
Not sure how this would be exposed, but driving Activity.getLifecycle events from the ReportFragment which is actually a different lifecycle to that Activity is very odd.
Not sure on the API, but a getActivityLifecycle and getFragmentLifecycle would be nice in this situation, as I actually want my lifecycle events to fire IN onCreate not in onStart.
ma...@marcardar.com <ma...@marcardar.com> #5
Hi, any news?
Description
**Version used:**
- navigationCompose = "2.8.5"
- androidxComposeBom = "2025.01.00"
**Devices/Android versions reproduced on:**
Android 14 Samsung devices:
- Samsung S23+
- Samsung A54
- Samsung A23
**This bug has occurred only 3 times, affecting 3 unique users.**
StackTrace:
```
Fatal Exception: java.lang.IllegalStateException: Cannot transition entry that is not in the back stack
at androidx.navigation.NavController$NavControllerNavigatorState.prepareForTransition(NavController.java:382)
at androidx.navigation.compose.ComposeNavigator.prepareForTransition(ComposeNavigator.kt:75)
at androidx.navigation.compose.NavHostKt$NavHost$25$1.invokeSuspend(NavHost.kt:519)
at androidx.navigation.compose.NavHostKt$NavHost$25$1.invoke(NavHost.kt:12)
at androidx.navigation.compose.NavHostKt$NavHost$25$1.invoke(NavHost.kt:12)
at androidx.activity.compose.OnBackInstance$job$1.invokeSuspend(PredictiveBackHandler.kt:121)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
```
Reproducibility:
The exact steps to reproduce this issue are unknown. Crash happened on different screen each time.
Important note:
The stack trace includes PredictiveBackHandler, even though Predictive Back Gestures are not enabled in my project.