question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tmp detached view should be removed from RecyclerView before it can be recycled

See original GitHub issue

Hi. I’m getting some random crashes in one particular screen of my app. The screen is a scrolling view of various movie details, and I use Epoxy to create it. This is the error reported in logcat:

java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled

A complete stack trace can be found here

Some Googling suggest the following solutions:

  1. Setting 'setHasStableIds = false` on the recycler view adapter but this option obviously does not apply to Epoxy. source
  2. Removing custom item animators on the RecyclerView, but I’m not using any. source

Here’s the Epoxy Model for which this error occurs:

@EpoxyModelClass(layout = R.layout.view_info_text)
abstract class InfoTextModel : EpoxyModelWithHolder<InfoTextModel.InfoTextViewHolder>() {

    @EpoxyAttribute
    lateinit var text: String

    override fun bind(holder: InfoTextViewHolder) {
        super.bind(holder)
        holder.textView.text = text
    }

    inner class InfoTextViewHolder : KotlinEpoxyHolder() {
        val textView by bind<TextView>(R.id.tvInfoText)
    }
}

Here’s the XML file for this model:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tvInfoText"
        style="@style/TextAppearance.MaterialComponents.Body2.EmptyViewTextStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="100dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_gravity="center"
        android:gravity="center"/>
</FrameLayout>

Here’s the relevant code in the Epoxy Controller:

actorsList.takeIf { list -> !list.isNullOrEmpty() }?.forEach { actorResource ->
                ...
    } ?: infoText {
            id("cast-empty")
            text("This list seems to be empty")
            spanSizeOverride { totalSpanCount, _, _ -> totalSpanCount }
    }

If you need complete sources, they can be found in this package on my Github repo

I’m not sure why does this error occur, or how to solve it. This seems to be a recycler view specific issue, but in my app I’m using the EpoxyRecyclerView class. Any help would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
premacckcommented, Dec 2, 2019

I was also getting bugged by this issue in production, turns out you shouldn’t use android:animateLayoutChanges="true" on the parent ViewGroup of the RecyclerView/EpoxyRecyclerView

After I removed that one line, everything runs like a peach!

8reactions
AndroidDeveloperLBcommented, Feb 2, 2020

This issue is quite known: https://stackoverflow.com/a/60024405/878126

I reported about this here: https://issuetracker.google.com/issues/148720682

Basically I think it’s RecyclerView not liking that you hide it while it’s still animating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView gets crashed [IllegalArgumentException] when ...
IllegalArgumentException : Tmp detached view should be removed from RecyclerView before it can be recycled: ViewHolder{41b7bec0 position=6 ...
Read more >
Recycler View crash when notifyItemRangeChanged() called ...
When you detach and scrap a view, it is NOT recycled. Instead it just waits to be rebound so if you call recycler.getViewForPosition,...
Read more >
RecyclerView.Recycler - Android Developers
A view must be fully detached (removed from parent) before it may be recycled. If the View is scrapped, it will be removed...
Read more >
Tmp detached view should be removed from RecyclerView ...
Tmp detached view should be removed from RecyclerView before it can be recycled:ViewHolder ; public final void ; ( · ); ...
Read more >
prevent recyclerview from recycling views
Tmp detached view should be removed from RecyclerView before it can be recycled:ViewHolder. lyldding-HFFW 2019-11-06 11:51:23 2526 收藏 1.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found