android保存view,Android 不想保存View的状态,使用这种方式可以么?

项目在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的状态了...哪位熟悉这方面的朋友能不能帮帮我

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值