Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
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.