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

@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全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Atlas框架下通过ViewPager+Fragment加载Bundle的Activity不能回调onActivityResult问题解决
现象:MainActivity通过ViewPager+Fragment加载装载HomeActivity、SearchActivity、CategoryActivity、CartActivity、MineActivity。若在HomeActivity内部的Fr……
<<上一篇
下一篇>>
文章目录
关闭
目 录