美文网首页
Fragment already active

Fragment already active

作者: 李新阳 | 来源:发表于2020-05-22 10:30 被阅读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,其实没解决,但避免了崩溃

相关文章

网友评论

      本文标题:Fragment already active

      本文链接:https://www.haomeiwen.com/subject/utafahtx.html