Fixed
Status Update
Comments
il...@google.com <il...@google.com>
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
an...@google.com <an...@google.com> #3
yea i'll take it.
jb...@google.com <jb...@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.
il...@google.com <il...@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()
}
}
Description
Version used: 1.2.2
Devices/Android versions reproduced on: Pixel 3 running Android 10
If a DialogFragment doesn't return a View in onCreateView then onViewCreated isn't called. In such case if one tries to use viewLifecycleOwner he's probably doing it in onCreateDialog or earlier. But using viewLifecycleOwner isn't possible before view is created. There is a lint error with a message that explains that. But this message doesn't take into account that it's a DialogFragment which should be treated differently (viewLifecycleOwner shouldn't be used). It would be good to detect that viewLifecycleOwner is being used in DialogFragment and show a better message.