Fixed
Status Update
Comments
al...@google.com <al...@google.com>
jb...@google.com <jb...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
sq...@gmail.com <sq...@gmail.com> #3
yea i'll take it.
ap...@google.com <ap...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
jb...@google.com <jb...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
am...@gmail.com <am...@gmail.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
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.