Fixed
Status Update
Comments
al...@google.com <al...@google.com>
jb...@google.com <jb...@google.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
sq...@gmail.com <sq...@gmail.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 82faca9ddbd48485b8752cc702891e45a00bcd92
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Jun 23 21:40:35 2021
Fix ActivityResultRegistry save/restore
The ActivityResultRegistry is currently restored after the on
ComponentActivity call to super.onCreate(). This means that any
callbacks registered before that could have already been saved waiting
to be restored so we end up improperly registering several duplicate
callbacks.
We should handle this on two fronts, one in ActivityResultRegistry for
cases outside of ComponentActivity and inside of ComponentActivity.
For ComponentActivity we should save earlier as part of an OnContextAvailableListener to ensure that we restore the callbacks as soon as possible.
For ActivityResultRegistry, we should make sure that even if we register
before a call on onRestoreInstanceState, we don't duplicate keys.
Specifically, we need to restore the old requestCode to ensure that any
launched results that could potentially be dispatched still have a valid
requestCode, otherwise the dispatch would be ignored.
RelNote: "The ActivityResultRegistry callbacks are now properly saved
and restored so callbacks are not duplicated in the savedState."
Test: Added new test
Bug: 191893160
Change-Id: I9781617370ad24f768249df42d2ab148915097cb
M activity/activity/src/androidTest/AndroidManifest.xml
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivityResultTest.kt
M activity/activity/src/androidTest/java/androidx/activity/result/ActivityResultRegistryTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/result/ActivityResultRegistry.java
https://android-review.googlesource.com/1745378
Branch: androidx-main
commit 82faca9ddbd48485b8752cc702891e45a00bcd92
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Jun 23 21:40:35 2021
Fix ActivityResultRegistry save/restore
The ActivityResultRegistry is currently restored after the on
ComponentActivity call to super.onCreate(). This means that any
callbacks registered before that could have already been saved waiting
to be restored so we end up improperly registering several duplicate
callbacks.
We should handle this on two fronts, one in ActivityResultRegistry for
cases outside of ComponentActivity and inside of ComponentActivity.
For ComponentActivity we should save earlier as part of an OnContextAvailableListener to ensure that we restore the callbacks as soon as possible.
For ActivityResultRegistry, we should make sure that even if we register
before a call on onRestoreInstanceState, we don't duplicate keys.
Specifically, we need to restore the old requestCode to ensure that any
launched results that could potentially be dispatched still have a valid
requestCode, otherwise the dispatch would be ignored.
RelNote: "The ActivityResultRegistry callbacks are now properly saved
and restored so callbacks are not duplicated in the savedState."
Test: Added new test
Bug: 191893160
Change-Id: I9781617370ad24f768249df42d2ab148915097cb
M activity/activity/src/androidTest/AndroidManifest.xml
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivityResultTest.kt
M activity/activity/src/androidTest/java/androidx/activity/result/ActivityResultRegistryTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/result/ActivityResultRegistry.java
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be part of both the Activity 1.3.0-rc02
and 1.2.4
releases.
am...@gmail.com <am...@gmail.com> #6
Hi 👋
Description
Component used: AppCompatActivity
Version used: 1.3.0
Devices/Android versions reproduced on: Emulator API 28, 30, Samsung Galaxy S21 API 30, most likely all versions are affected
Each time I change the orientation of my screen, the saved instance bundle size increases by 3 elements in two different ArrayLists.
Here is the minimal example that will illustrate the issue. The additional code in the
onSaveInstanceState
is only there to display the issue.Here is the full output when rotated 6 times:https://pastebin.com/yfE04Fmc
Mini-extract (2 rotations):
As you can see, each time the screen is rotated, 3 elements are added to these two entries. After rotating the screen for a while, the instance state becomes significantly bigger for no apparent reason.
I traced it back to (but can be wrong)
ActivityResultRegistry
, and it seems that something in the support library doesn't clean up the state with the registry.I also tried simply putting the app in the background, which triggers the
onSaveInstanceState
but that did not increase the bundle size. It looks like the activity must be re-created.When I inherit from
Activity
instead, the issue disappears.