gabin
03/06/2020, 10:16 AMsatyan
03/06/2020, 11:18 AMviewModelScope{}
but livedata{}
is used to create a Livedata using the ViewModel coroutine scope. (Using emit
to emit values or emitSource
to emit values from another Livedata)
The viewmodelScope
is a CoroutineScope scoped by the ViewModel lifecycle.gabin
03/06/2020, 12:12 PMviewModelScope{}
survives it, but I am not sure about livedata{}
. Lets say I made a network request inside livedata{}
and rotated screen couple of times - will the result arrive to observer ? Will it be cancelled if viewModel is destroyed and I moved to another activity?satyan
03/06/2020, 12:25 PMAdam Powell
03/06/2020, 1:58 PMliveData {}
will stay alive for as long as the resulting LiveData
has active observers, plus a configurable timeout. The default is non-zero and you can change it with a parameter to the liveData {}
builder. Therefore if you start re-observing the same LiveData
instance after a config change before the timeout expires, yes, the work happening in that block will continue.satyan
03/06/2020, 2:04 PM