有时我的应用在更新RecyclerView行中上传视频的进度时崩溃-Android。

13

我正在上传一个视频并在recyclerview中显示进度,我们可以上传多个视频并显示它们的进度单独,如果我们切换页面或进入app,上传应该继续(不停止)。

问题出现了 - 在更新recyclerView中的进度时,应用程序有时会崩溃(recyclerView在带有TAB布局和viewPager的片段中)

我正在使用广播接收器来解决这个问题

下面是代码:

 try {
        for (int i = 0; i < postList.size(); i++) {
            if (postList.get(i).getId().equals(postId)) {
                postList.get(i).setProgress(result.getProgress());
                profileListAdapter.notifyItemChanged(i);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

日志记录器

Fatal Exception: java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled: ViewHolder{cc90564 position=1 id=-1, oldPos=-1, pLpos:-1 update tmpDetached no parent}
   at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5238)
   at android.support.v7.widget.RecyclerView.removeAnimatingView(RecyclerView.java:1198)
   at android.support.v7.widget.RecyclerView$ItemAnimatorRestoreListener.onAnimationFinished(RecyclerView.java:10834)
   at android.support.v7.widget.RecyclerView$ItemAnimator.dispatchAnimationFinished(RecyclerView.java:11334)
   at android.support.v7.widget.SimpleItemAnimator.dispatchAddFinished(SimpleItemAnimator.java:289)
   at android.support.v7.widget.DefaultItemAnimator$5.onAnimationEnd(DefaultItemAnimator.java:242)
   at android.support.v4.view.ViewPropertyAnimatorCompatJB$1.onAnimationEnd(ViewPropertyAnimatorCompatJB.java:47)
   at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1114)
   at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1239)
   at android.animation.ValueAnimator.cancel(ValueAnimator.java:1140)
   at android.view.ViewPropertyAnimator.cancel(ViewPropertyAnimator.java:427)
   at android.support.v4.view.ViewPropertyAnimatorCompatICS.cancel(ViewPropertyAnimatorCompatICS.java:102)
   at android.support.v4.view.ViewPropertyAnimatorCompat$ICSViewPropertyAnimatorCompatImpl.cancel(ViewPropertyAnimatorCompat.java:464)
   at android.support.v4.view.ViewPropertyAnimatorCompat.cancel(ViewPropertyAnimatorCompat.java:1063)
   at  

显示此错误

java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled: 
ViewHolder{cc90564 position=1 id=-1, oldPos=-1, pLpos:-1 update tmpDetached no parent}

注意:

我在我的应用程序中没有使用getSwipeableContainerViewadapter.setHasStableIds(true)

行的设计: 像这样的recyclerView
像这样的 recyclerView 行


https://dev59.com/_l0a5IYBdhLWcg3wqKKq - AskNilesh
@Nilesh 我已经检查过了,但是没有找到任何解决方案。 - Mr. Ad
尝试使用setUserVisibleHint()方法,在包含列表的片段对用户可见时通知行。 - avinash
1个回答

3
尝试使用notifyDataSetChanged()替代notifyItemChanged(i)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接