Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GapWorker with Scrapped or attached views may not be recycled. isScrap:false isAttached:true

When i scroll my recyclerview too fast i am getting the following crash

 java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true
                                                                 at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5659)
                                                                 at android.support.v7.widget.RecyclerView$Recycler.recycleView(RecyclerView.java:5603)
                                                                 at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:277)
                                                                 at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:324)
                                                                 at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:337)
                                                                 at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:344)
                                                                 at android.support.v7.widget.GapWorker.run(GapWorker.java:370)
                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I had tried my every effort and get similar question on stackoverflow, but none of them were helpful like following links,

Link 1

Link 2

Link 3

Link 4

Link 5

I have no knowledge of this crash from where it is occurring. Any help would be greatly appreciated. I am neither using "android:animateLayoutChanges="true"

Basically i had tried to merge these two different GitHub project,

rv-adapter-states

rv-adapter-endless

My files links are as follows from pastbin,

Row Layout

Code of recyclerview

My Adapter merge from two diffrent adapter of rv

Main adapter

like image 780
Reprator Avatar asked Dec 31 '16 11:12

Reprator


2 Answers

I had the same problem and I don't know why is happening.

I solved it removing the android:animateLayoutChanges on the recyclerview and to animate the recyclerview I have added: recyclerView.setItemAnimator(new DefaultItemAnimator());

Take an account to add the method public long getItemId(int position) and set setHasStableIds(true) if you want animate it.

like image 200
aLx Avatar answered Sep 22 '22 05:09

aLx


Have you tried layoutManager.setItemPrefetchEnabled(false);? It worked for me.

like image 31
asamoylenko Avatar answered Sep 25 '22 05:09

asamoylenko