Assigned
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@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
il...@google.com <il...@google.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.
ch...@instacart.com <ch...@instacart.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.
ne...@gmail.com <ne...@gmail.com> #5
Hi, any news?
sk...@gmail.com <sk...@gmail.com> #6
Hello Ian,
any chance to fix this by just returning the already existing mFragmentLifecycleRegistry
in getLifecycle()
overload?
This really caused us back-press handling issues as mentioned in my
Currently I'm workarounding this with a reflection to register the callback with mFragmentLifecycleRegistry
lifecycle.
Thank you.
ju...@veepee.com <ju...@veepee.com> #7
Is this ever going to be implemented? My team is facing issues related to this as well... Be it with registering OnBackPressed on orientation changes or driving the ViewLifecycle in some cases...
Description
Version used:
Devices/Android versions reproduced on:
Driving Fragment Lifecycle methods with methods from LifecycleObserver would make the connection between their behavior more obvious, and would fix inconsistency of calling order between Fragment.onStop and Fragment.onSaveInstanceState in Android <28 vs Android 28+