Fragment already active

2020-05-22  本文已影响0人  李新阳

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/Fragment.java

使用fragment做抖音上下滑动切换发生的,查看源码有两个位置会发生

public void setArguments(Bundle args) {
// The isStateSaved requirement below was only added in Android O and is compatible
// because it loosens previous requirements rather than making them more strict.
// See method javadoc.
if (mIndex >= 0 && isStateSaved()) {
throw new IllegalStateException("Fragment already active");
}
mArguments = args;
}

public void setInitialSavedState(SavedState state) {
if (mIndex >= 0) {
throw new IllegalStateException("Fragment already active");
}
mSavedFragmentState = state != null && state.mState != null
? state.mState : null;
}

第一种可以用set方法传值避免,第二种不好解决,我是在
pageradapter调用instantiateItem方法是try catch,其实没解决,但避免了崩溃

上一篇 下一篇

猜你喜欢

热点阅读