项目在Fragment切换中出现一个关于View onRestoreInstance()的错误,目前原因没有查到...
出现Crash的地方:
这个IllegalArguementExp导致在部分机型上产生Crash...
// ~ View.java
@CallSuper
protected void onRestoreInstanceState(Parcelable state) {
mPrivateFlags |= PFLAG_SAVE_STATE_CALLED;
if (state != null && !(state instanceof AbsSavedState)) {
/// 提示什么 sameid, 但是目前没有发现有重复的Id
// 可能原因是Fragment恢复状态时,导致View(RecyclerView)出现了这个问题
throw new IllegalArgumentException("Wrong state class, expecting View State but "
+ "received " + state.getClass().toString() + " instead. This usually happens "
+ "when two views of different type have the same id in the same hierarchy. "
+ "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure "
+ "other views do not use the same id.");
}
if (state != null && state instanceof BaseSavedState) {
mStartActivityRequestWho = ((BaseSavedState) state).mStartActivityRequestWhoSaved;
}
}
我想得解决方法就是重写这个RecyclerView的onSaveInstance()
, 代码如下
// ~ 自定义RecyclerView中
@Override
protected Parcelable onSaveInstanceState() {
super.onSaveInstanceState();
// 返回一个空State,相当于没有保存RecyclerView的状态
return BaseSavedState.EMPTY_STATE;
}
切换Fragment时偶现的Crash解决了,但是不知道会不会引起其他问题?... 因为我没有保存RecyclerView的状态了...哪位熟悉这方面的朋友能不能帮帮我