Atlas框架下通过ViewPager+Fragment加载Bundle的Activity不能回调onActivityResult问题解决
现象:MainActivity
通过ViewPager+Fragment
加载装载HomeActivity
、SearchActivity
、CategoryActivity
、CartActivity
、MineActivity
。若在HomeActivity
内部的Fragment启动新的Bundle Activity,当返回时,Activity生命周期的焦点在MainActivity
上
MainActivity
不能回调onActivityResult
HomeActivity
不能回调onActivityResult
HomeActivity
中的Fragment不能回调onActivityResult
MainActivity
的onResume
可以回调
可通过Host与Bundle间通信机制解决HomeActivity及其内部Fragment的回调,如RxBus
MainActivity
@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
@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;
}
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/activity-of-loading-bundles-through-viewpager-fragment-in-atlas-framework-cannot-call-back-onactivityresult/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论