Fixed
Status Update
Comments
il...@google.com <il...@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> #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.
na...@google.com <na...@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
Component used: androidx.lifecycle.viewmodel
Version used: 2.5.0
Description:
Since lifecycle 2.5.0,
ViewModelProvider
createsViewModel
instance withViewModelFactory.create(modelClass, extra)
method if this method is implemented.In
ViewModelProvider.AndroidViewModelFactory
class case, it provides both ofcreate(modelClass, extra)
andcreate(modelClass)
, but it will always usecreate(modelClass, extra)
only.create(modelClass)
method is not used anymore if class is inherited fromViewModelProvider.AndroidViewModelFactory
,ViewModelProvider.AndroidViewModelFactory.create(modelClass)
create(modelClass)
method only instead ofcreate(modelClass, extra)
forViewModelProvider.AndroidViewModelFactory
class.