草庐IT

DiffResult

全部标签

android - DiffResult 调度有时会导致 'Inconsistency detected. Invalid view holder adapter positionViewHolder' 错误

我有一个接受两个列表的RxJava2Observable,计算它们的差异结果并将此数据发送到适配器。适配器在主线程上分派(dispatch)更新。适配器中的调度代码:publicvoiddispatchStreams(Liststreams,@NullableDiffUtil.DiffResultdiffResult){if(streams==null)return;streamsList.clear();streamsList.addAll(streams);if(diffResult!=null){diffResult.dispatchUpdatesTo(this);}}我发现“检

android - RecyclerView 和 DiffUtil - 并发噩梦

ThedocumentationforDiffUtil建议生成DiffUtil.DiffResult由于潜在的长计算时间,在后台线程上。这对我来说似乎是个坏主意,因为该线程可能在以下情况下对陈旧数据进行操作(假设list访问是线程安全的):将数据添加到list并通知适配器需要更换list与newList这将有一些添加和一些删除的差异调用DiffUtil.calculateDiff在后台获取DiffResult对于list和newList,并向将使用newList的主线程发布消息并调用DiffResult.dispatchUpdatesTo在处理该消息之前,用户在主线程上执行了一项操作,