Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同一个key且同一个observer会重复订阅 #154

Open
zhafeite opened this issue Feb 22, 2022 · 1 comment
Open

同一个key且同一个observer会重复订阅 #154

zhafeite opened this issue Feb 22, 2022 · 1 comment

Comments

@zhafeite
Copy link

同一个key且同一个observer会重复订阅

@zhanf
Copy link

zhanf commented Sep 19, 2022

确实,比如在 onResume 订阅会出现重复订阅,android 系统 LiveEvent 不会,因为有重复判断。

@mainthread
private void observeInternal(@nonnull LifecycleOwner owner, @nonnull Observer observer) {
ObserverWrapper observerWrapper = new ObserverWrapper<>(observer);
observerWrapper.preventNextEvent = liveData.getVersion() > ExternalLiveData.START_VERSION;
liveData.observe(owner, observerWrapper);
}

而LiveEventBus 每次订阅都会重新创建 ObserverWrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants