Fixed
Status Update
Comments
ap...@google.com <ap...@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
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.
lb...@gmail.com <lb...@gmail.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()
}
}
jb...@google.com <jb...@google.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)
lb...@gmail.com <lb...@gmail.com> #7
yea sorry immediate does not fix it.
I actually have a WIP fix for it:
https://android-review.googlesource.com/c/platform/frameworks/support/+/1112186
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
jb...@google.com <jb...@google.com> #8
Project: platform/frameworks/support
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
https://android-review.googlesource.com/1112186
https://goto.google.com/android-sha1/af12e75e6b4110f48e44ca121466943909de8f06
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
as...@google.com <as...@google.com> #9
Hi
na...@google.com <na...@google.com> #10
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.7.0-alpha05
androidx.transition:transition:1.5.0-alpha03
lb...@gmail.com <lb...@gmail.com> #11
@8 Not sure I see there about Fragments in navigation component, of how to handle it there.
It's mostly about Activities.
Also, speaking of Activities, I can't find a way to support it only to some Activities. Currently it's all-or-nothing, making it very hard to migrate to it and also reduce the appeal of migrating to it (as it requires the entire project to migrate, instead of just what matters).
@9 Please also show samples in fragments within navigation.
In the past when I talked about it, Google actually said (maybe even here in the issue tracker) that it's denied and won't be added.
I don't understand what's going on now.
It's mostly about Activities.
Also, speaking of Activities, I can't find a way to support it only to some Activities. Currently it's all-or-nothing, making it very hard to migrate to it and also reduce the appeal of migrating to it (as it requires the entire project to migrate, instead of just what matters).
@9 Please also show samples in fragments within navigation.
In the past when I talked about it, Google actually said (maybe even here in the issue tracker) that it's denied and won't be added.
I don't understand what's going on now.
as...@google.com <as...@google.com> #12
Hi
We are planning on publishing a set of samples showing fragment animations. You'll be able to find them in
lb...@gmail.com <lb...@gmail.com> #13
@12 Was it added recently? I don't remember seeing this.
About the samples, please also add for navigation and maybe also for the navigation-drawer sample.
Even better if you put it in the templates of a new Activity, as this way you could encourage developers to do it.
About the samples, please also add for navigation and maybe also for the navigation-drawer sample.
Even better if you put it in the templates of a new Activity, as this way you could encourage developers to do it.
as...@google.com <as...@google.com> #14
Yes, per-activity opt-in is new in Android 14 and so this portion of the guide was added recently. Thank you for your feedback -- we'll take it into consideration.
lb...@gmail.com <lb...@gmail.com> #15
Comment has been deleted.
lb...@gmail.com <lb...@gmail.com> #16
@14 OK thank you. I wish you'd restore some of the templates there, to show how to use them nowadays.
I learn better from tiny samples than large ones. And those that are shown "on the way" right in the templates of the IDE mean you are serious about them.
Please make sure that we can have all of the possible behaviors of the Predictive Back Gesture when used in a fragment withing the navigation graph:
1. Show the fragment that we will go to when trying to go back
2. Block going to previous fragment (either doesn't exist, or exist and we choose not to allow it) and instead show what's behind in terms of Activity (or app), instead (leaving the current Activity/app)
3. Block back gesture completely, not allowing to go back
Will you please also fix the countless of weird exceptions that appear to this day even on Android 14, related to foreground service?
I've been struggling with it for a very long time. Even found some scenarios for some of the exceptions to occur, and some even contradict the documentation, including even on Pixel devices...
I learn better from tiny samples than large ones. And those that are shown "on the way" right in the templates of the IDE mean you are serious about them.
Please make sure that we can have all of the possible behaviors of the Predictive Back Gesture when used in a fragment withing the navigation graph:
1. Show the fragment that we will go to when trying to go back
2. Block going to previous fragment (either doesn't exist, or exist and we choose not to allow it) and instead show what's behind in terms of Activity (or app), instead (leaving the current Activity/app)
3. Block back gesture completely, not allowing to go back
Will you please also fix the countless of weird exceptions that appear to this day even on Android 14, related to foreground service?
I've been struggling with it for a very long time. Even found some scenarios for some of the exceptions to occur, and some even contradict the documentation, including even on Pixel devices...
lb...@gmail.com <lb...@gmail.com> #17
@14 The blocking to going to previous Fragment is important in case the previous Fragment is used as a way to choose which Fragment to reach, and not as UI.
This is something that was said to use instead of clearing the stack itself:
https://issuetracker.google.com/issues/109909461#comment5
https://developer.android.com/guide/navigation/use-graph/conditional
So you wouldn't want to show the MainFragment there, and instead you'd want to allow to skip directly to the Activity behind, even though MainFragment is in the back-stack of the navigation.
Sadly even there on this documentation, there is no sample and there is a lot of missing code.
This is something that was said to use instead of clearing the stack itself:
So you wouldn't want to show the MainFragment there, and instead you'd want to allow to skip directly to the Activity behind, even though MainFragment is in the back-stack of the navigation.
Sadly even there on this documentation, there is no sample and there is a lot of missing code.
Description
API 34 provided a new Predictive Back Gesture that allows seeking when going back and provides a View of the previous Activity.
Now that this feature is available between Activities it would be nice if it was also available between Fragments. Fragments need to handle multiple effects system to get this working and this bug will focus on providing support for Transitions.