Here I have written a MutableLiveList<T>
class that is intended to replace MutableLiveData<MutableList<T>>
in my project. This is working fine till now. But if multiple modifications are done to the list when that activity is in inactive state, then only the last modification to that list will trigger adapter notify methods. In this case I don't know will the app crash. So I needed to mimic that situation exactly. When the screen rotates, activity gets destroyed and recreated. But I don't know how to add items to that list between that interval. Anyone please help me. Or tell me a better way to do it.
Is there any guarenteed way to mimic some action between `onDestroy()` and `onCreate()` methods of an activity being recreated?
68 views Asked by Sourav Kannantha B At
1
You could add them in the activity's
onDestroy
callback function. At that point the activity'sLifecycle
object is either in theCREATED
orDESTROYED
state:Point is it's not in the
STARTED
state at that point, and:So by the time you're in
onDestroy
, any observer using that activity'sLifecycle
won't see any updates from theLiveData
. So you should be able to add values to theLiveData
without getting notified.By the way, that "only notified of the last value" update is by design:
So if the data goes
A, B, C
while the observer is inactive, it won't be notified of those values. When it goes from inactive to inactive, it'll get the most recent value,C
. It doesn't save a history of all the values an observer has missed