Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
te...@gmail.com <te...@gmail.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
cl...@google.com <cl...@google.com>
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.
te...@gmail.com <te...@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()
}
}
na...@google.com <na...@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)
pr...@google.com <pr...@google.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} )
}
Description
Version used: 2.6.0
Devices/Android versions reproduced on: every device & tested in above SDK 23
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
Issue:
When using navigation component in fragment, the destination fragment's viewModel (which configured savedState & restoreState) is not cleared even though the destination popped from backstack.
For clearing destination's VM, I should call `navController.clearBackStack(destinationId)`.
I know It is intended feature for preserving VM's state for later restore.
However, the problem happens in the situation that the destination fragment has nested fragment and nested fragment has its VM (call nested VM).
Nested VM never cleared when call `navController.clearBackStack(destinationId)` of parent fragment.
Sadly, VM never cleared even though activity is destroyed. (if application not terminated)
I attached sample project and screen record for reproduce.