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

返回栈最上方的Activity发送事件后,返回栈最底下(中间隔了好几个Activity)的订阅者无法接收到订阅事件 #6

Closed
ChenJia-X opened this issue Aug 16, 2018 · 3 comments

Comments

@ChenJia-X
Copy link

大佬,请教一个问题

HomeActivity首页由多个Fragment组成,通过 NavigationController切换。
在HomeActivity中如下订阅事件:

RxBusManager.subscribeEnquiryOrOrderList(this, new RxBus.Callback<String>() {
    @Override
    public void onEvent(String s) {
        switch (s) {
            case ENQUIRY_AUTO:
                navigationController.setSelect(1);
                checkPriceListFragment.jump(s);
                break;
            case ENQUIRY_MANUAL:
                navigationController.setSelect(1);
                checkPriceListFragment.jump(s);
                break;
            case ORDER_AUTO:
                navigationController.setSelect(2);
                orderFragment.jump(s);
                break;
            case ORDER_MANUAL:
                navigationController.setSelect(2);
                orderFragment.jump(s);
                break;
        }
    }
});

然后连续打开了3个Activity,在第三个Activity中发送事件,并依次finish这3个Activity。

//跳转到人工询价列表
RxBusManager.postToEnquiryOrOrderList(ENQUIRY_MANUAL);
ActivityManager.removeActivitis(new String[]{"CActivity", "BActivity", "AActivity"});

但是HomeActivity并不会接收到该事件,这是什么原因?是我的使用方式有问题吗?

我在只跨一个Activity的情况下,这种使用方式是可行的,而且是先调用finish再发送订阅事件。

@ChenJia-X
Copy link
Author

我搞错了,只跨一个Activity的情况也是不行的。

我想请教下,跨Activity能否实现发送和接受订阅事件?

@ChenJia-X
Copy link
Author

使用sticky的post和subscribe成功实现了这个需求。

但是逻辑上我还是有点疑惑,HomeActivity中先subscribe,为什么会接收不到后post的事件?

@Blankj
Copy link
Owner

Blankj commented Aug 28, 2018

正常订阅之后就可以收到,如果要先发送后订阅那就用 sticky,实现是没有问题的,你可以自己打 Log 或者断点调试测试。

@Blankj Blankj closed this as completed Aug 28, 2018
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