Status Update
Comments
fl...@googlemail.com <fl...@googlemail.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit c2365dcfeb9064814282304f30f3eb86be71fdc7
Author: Dan Nizri <dniz@google.com>
Date: Wed Dec 20 16:33:08 2023
Fix Popup back handling on Android T/13+ when android:enableOnBackInvokedCallback="true"
Bug: 313702338
Bug: 318537200
Test: tested with android:enableOnBackInvokedCallback="true"
Change-Id: I7c7cef686ed9fbfd2d144c90040b13528f1675ed
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt
https://android-review.googlesource.com/2886766
Branch: androidx-main
commit c2365dcfeb9064814282304f30f3eb86be71fdc7
Author: Dan Nizri <dniz@google.com>
Date: Wed Dec 20 16:33:08 2023
Fix Popup back handling on Android T/13+ when android:enableOnBackInvokedCallback="true"
Bug: 313702338
Bug: 318537200
Test: tested with android:enableOnBackInvokedCallback="true"
Change-Id: I7c7cef686ed9fbfd2d144c90040b13528f1675ed
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt
Description
Information
Component used: Activity Version used: 1.3.1 Devices/Android versions reproduced on:
Problem description
OnBackPressedDispatcher::addCallback
clearly states that theUnfortunately the callback order is not restored properly after orientation change, if the callback of a Fragment was added "deferred".
I have attached a little project where the bug can be reproduced:
A
MainActivity
containing aMainFragment
, which gets added deferred (2000 ms). Both the Activity and the Fragment adds anOnBackPressedCallback
.A breakpoint was set in
OnBackPressedDispatcher::addCancellableCallback
Line 117 to verify the order. This method gets called to finally add the callbacks, if the lifecycle is set to a certain state (CREATED).If the Application is started, the callback order is
if the device is rotated, the order gets restored as
So the callback order is no longer guaranteed to be in reverse order in which they are added.
Note: if the Fragment is added immediately upon creation of the Activity, the order was restored properly! So the "bug" (I suppose) only occurs if the add-action of a Fragment is deferred.
I have prepared code for both cases in the sample application. (Search for
TODO
and see the comments in theMainActivity
).Expectation
I would have expected that the order in which the callbacks are added is the same after orientation change as it was before. Regardless if the callback was added at a certain time, the order should be kept the same as right before the orientation change.