从 MediatorLiveData 中删除源时,关联的观察者是否也会被删除?

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

从 MediatorLiveData 中删除源时,是否也会删除关联的观察者?

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);

是的,当您调用 removeSource 时,Observer 回调被移除。

内部调用:

mLiveData.removeObserver(this);

您可以检查行 hereunplug() 函数是从 removeSource

调用的