Atlas插件bundle与host通信之RxBus

在bundle中注册RxBus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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中发送消息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@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;
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :