使用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,其实没解决,但避免了崩溃