When removing a source from MediatorLiveData, does the associated Observer get removed as well?

441 Views Asked by At

When removing a source from MediatorLiveData, does the associated Observer get removed as well?

private final MediatorLiveData<Model> liveModel = new MediatorLiveData<>();
private LiveData<ModelEntity> liveData = repository.getModelEntity();

    liveModel.addSource(liveData , new Observer<ModelEntity>() {
        @Override
        public void onChanged(ModelEntity modelEntity) {}
    });

liveModel.removeSource(liveData);
1

There are 1 best solutions below

0
On BEST ANSWER

Yes, when you call removeSource the Observer callback is removed.

Internally it calls:

mLiveData.removeObserver(this);

You can check the line here, unplug() function is called from removeSource