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

事件被内部吞掉,导致不回调问题 #160

Open
liujingxing opened this issue Oct 26, 2022 · 0 comments
Open

事件被内部吞掉,导致不回调问题 #160

liujingxing opened this issue Oct 26, 2022 · 0 comments

Comments

@liujingxing
Copy link

liujingxing commented Oct 26, 2022

在内部LiveData有值的情况下,Activity#onCreate方法里订阅事件,并立即发送事件,此时将收不到任何回调,代码如何:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LiveEventBus.get("test").post("value1"); //保证内部LiveData有值

        LiveEventBus.<String>get("test").observe(this, new Observer<String>() {
            @Override
            public void onChanged(String value) {
                Log.e("LJX", "value=" + value);
            }
        });
        LiveEventBus.get("test").post("value2");
    }
}

此时将收不到任何回调,查看源码后发现,是被ObserverWrapper#preventNextEvent拦截了,该字段本意应该是拦截粘性事件,但在这种情况下,却会拦截订阅后的事件

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

1 participant