Atlas框架下通过ViewPager+Fragment加载Bundle的Activity不能回调onActivityResult问题解决

现象:MainActivity通过ViewPager+Fragment加载装载HomeActivitySearchActivityCategoryActivityCartActivityMineActivity。若在HomeActivity内部的Fragment启动新的Bundle Activity,当返回时,Activity生命周期的焦点在MainActivity

  • MainActivity不能回调onActivityResult
  • HomeActivity不能回调onActivityResult
  • HomeActivity中的Fragment不能回调onActivityResult
  • MainActivityonResume可以回调

可通过Host与Bundle间通信机制解决HomeActivity及其内部Fragment的回调,如RxBus

MainActivity

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
protected void onResume() {
super.onResume();
NLog.i(TAG, "MainActivity: onResume");
onBundleActivityResume(mViewPager.getCurrentItem());
}

private void onBundleActivityResume(int position) {
NLog.i(TAG, "MainActivity: onBundleActivityResume " + position);
switch (position) {
case Constants.MAIN_TAB_HOME:
RxBus.getInstance().post(RxBus.TAG_HOME_RESUME, "home");
break;
case Constants.MAIN_TAB_SEARCH:
RxBus.getInstance().post(RxBus.TAG_SEARCH_RESUME, "search");
break;
case Constants.MAIN_TAB_CATEGORY:
RxBus.getInstance().post(RxBus.TAG_CATEGORY_RESUME, "category");
break;
case Constants.MAIN_TAB_CART:
RxBus.getInstance().post(RxBus.TAG_CART_RESUME, "cart");
break;
case Constants.MAIN_TAB_MINE:
RxBus.getInstance().post(RxBus.TAG_MINE_RESUME, "mine");
break;
default:
break;
}
}

HomeActivity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@RxBusSubscribe(tag = RxBus.TAG_HOME_RESUME)
public void onHomeActivityResume(String tab) {
NLog.i(TAG, "HomeActivity: onHomeActivityResume");
switch (mHomeViewPager.getCurrentItem()) {
case 0:

break;
case 1:

break;
case 2: //Collect
mHomeCollectFragment.refreshCollectGoodsList();
break;
default:
break;
}
}

Powered by AppBlog.CN     浙ICP备14037229号

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

访客数 : | 访问量 :