ViewPagerIndicator icon indicating copy to clipboard operation
ViewPagerIndicator copied to clipboard

java.lang.IllegalStateException

Open V-sign opened this issue 6 years ago • 4 comments

Fragment *** is not currently in the FragmentManager 请问这个问题如何解决?

V-sign avatar Oct 31 '18 09:10 V-sign

检查一下FragmentManager 是否用错了, fragment里面的fragment的getChildFragmentManager()方法 Activity内的用Activity的的getSupportFragmentManager()方法

LuckyJayce avatar Oct 31 '18 11:10 LuckyJayce

getChildFragmentManager()会导致这个问题 getSupportFragmentManager()会导致 java.lang.IllegalStateException: FragmentManager is already executing transactions 最后只能在 activity 里面加载 viewpager...

V-sign avatar Nov 01 '18 02:11 V-sign

@LuckyJayce 请问 FragmentListPageAdapter.finishUpdate 中为什么要调用 mFragmentManager.executePendingTransactions() 呢? 我不明白这里为什么和官方 support 库中的实现不同。

    public void finishUpdate(ViewGroup container) {
        if (mCurTransaction != null) {
            mCurTransaction.commitAllowingStateLoss();
            mCurTransaction = null;
            mFragmentManager.executePendingTransactions();
        }
    }

官方 support 包中的对应方法为:

    public void finishUpdate(@NonNull ViewGroup container) {
        if (this.mCurTransaction != null) {
            this.mCurTransaction.commitNowAllowingStateLoss();
            this.mCurTransaction = null;
        }
    }

baoti avatar Mar 25 '19 15:03 baoti

@LuckyJayce 我知道了,它们的行为是基本一致的。commitNowAllowingStateLoss() 也会立即执行当前 transaction。

baoti avatar Mar 26 '19 04:03 baoti