Search code examples
androidmvvmmutablelivedata

Post multiple MutableLiveData have no order


I'm using multiple MutableLiveData on an MVVM architecture. on the ViewModel, I post the objects but the fragment is not resumed. when the fragment has resumed the observers get the MutableLiveData but not in the order I post them. How can I force an order of getting the MutableLiveData?

ViewModel:

void foo(){

first_MutableLiveData.post(newData)

second_MutableLiveData.post(newData)

}

fragment:

initView(){

first_MutableLiveData.observe(this,()->{
"getting called second"})

second_MutableLiveData.observe(this,()->{
"getting called first"})

}

Solution

  • So apparently when I changed the observer's order on the fragment they arrived in the order I needed them to be. Thanks everyone for the quick response!