Atlas插件bundle与host通信之RxBus

在bundle中注册RxBus

public class HomeActivity extends TabMainActivity<HomePresenter> implements
        IHomeView {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NLog.i(TAG, "appblog_cn_home.ui.activity.HomeActivity");
        setContentView(R.layout.activity_home);
        initView();

        RxBus.getInstance().register(this);
    }

    @Override
    public HomePresenter createPresent() {
        return new HomePresenter();
    }

    private void initView() {

    }

    @RxBusSubscribe(tag = RxBus.TAG_HOME)
    public void onHomeTabSwitch(String tab) {
        NLog.i(TAG, "HomeActivity: onHomeTabSwitch");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxBus.getInstance().unRegister(this);  //注意销毁时取消注册,否则会出现重复多次回调接收
    }
}

在host中发送消息

@Override
public void onPageSelected(int position) {
    NLog.i(TAG, "ViewPager onPageSelected: " + position);

    onTabSwitch(position);
}

private void onTabSwitch(int position) {
    NLog.i(TAG, "MainActivity: onTabSwitch " + position);
    switch (position) {
        case Constants.MAIN_TAB_HOME:
            RxBus.getInstance().post(RxBus.TAG_HOME, "home");
            break;
        case Constants.MAIN_TAB_SEARCH:
            RxBus.getInstance().post(RxBus.TAG_SEARCH, "search");
            break;
        case Constants.MAIN_TAB_CATEGORY:
            RxBus.getInstance().post(RxBus.TAG_CATEGORY, "category");
            break;
        case Constants.MAIN_TAB_CART:
            RxBus.getInstance().post(RxBus.TAG_CART, "cart");
            break;
        case Constants.MAIN_TAB_MINE:
            RxBus.getInstance().post(RxBus.TAG_MINE, "mine");
            break;
        default:
            break;
    }
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/communication-between-atlas-plugin-bundle-and-host-rxbus/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Atlas插件bundle与host通信之RxBus
在bundle中注册RxBus public class HomeActivity extends TabMainActivity<HomePresenter> implements IHomeView { @Override protect……
<<上一篇
下一篇>>
文章目录
关闭
目 录