glide icon indicating copy to clipboard operation
glide copied to clipboard

You cannot start a load for a destroyed activity: on clear

Open Shakezulla57 opened this issue 8 years ago • 6 comments

Glide Version: 4.3.1

Device/Android Version: S8, S7, Pixel

Issue details / Repro steps / Use case background:

Similar to #138 and #803

I've never gotten this error until I updated to v4 and started using the generated api. The only code that got changed was specific to the refactor required for the library update. The odd thing is that the crash appears to be happening on the clear method and not the actual load. I'm only seeing the crash as it pertains to usage in a RecyclerView.

I'm using the FastAdapter library for my recyclerviews.

Glide load line / GlideModule (if any) / list Adapter code (if any):

@GlideModule
class AppGlideModule : AppGlideModule() {}

// how it is being loaded in bindView
 GlideApp
            .with(holder.itemView.context)
            .asBitmap()
            .load(profilePicture)
            .circleCrop()
            .placeholder(R.drawable.basic_circle_loader_animation)
            .into(holder.itemView.profile_pic)

// how its being cleard in unbindView
GlideApp.with(holder.itemView.context).clear(holder.itemView.profile_pic)

Stack trace / LogCat:

Fatal Exception: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:302)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:127)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:112)
       at com.bumptech.glide.Glide.with(Glide.java:609)
       at com.my.app.GlideApp.with(GlideApp.java:70)
       at com.my.app.Item.bindView(Item.kt:156)
       at com.my.app.Item.unbindView(Item.kt:28)
       at com.mikepenz.fastadapter.listeners.OnBindViewHolderListenerImpl.unBindViewHolder(OnBindViewHolderListenerImpl.java:51)
       at com.mikepenz.fastadapter.FastAdapter.onViewRecycled(FastAdapter.java:706)
       at android.support.v7.widget.RecyclerView$Recycler.dispatchViewRecycled(RecyclerView.java:6190)
       at android.support.v7.widget.RecyclerView$Recycler.addViewHolderToRecycledViewPool(RecyclerView.java:5961)
       at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5922)

Shakezulla57 avatar Dec 06 '17 15:12 Shakezulla57

Not much has changed here, it looks like onViewRecycled is just being called after onDestroy.

You can try memoizing the RequestManager:

RequestManager requestManager = Glide.with(fragment);
requestManager.load(...

If this is reproducible in a sample app I'd be happy to take a look. Although we can't easily start new loads from destroyed activities, in some circumstances it's plausible we could clear the Targets.

sjudd avatar Dec 06 '17 16:12 sjudd

Thanks for the feedback @sjudd. If I keep a reference to my GlideRequest what is the most efficient way to clear the load in the adapter unbindView? I can't find anything in the samples that clears it in this way.

Shakezulla57 avatar Dec 06 '17 17:12 Shakezulla57

Keep a reference to the RequestManager, not to the GlideRequest.

Then just requestManager.clear(imageView) is fine.

sjudd avatar Dec 07 '17 02:12 sjudd

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

stale[bot] avatar Dec 14 '17 02:12 stale[bot]

i have same issues with this, and i have been solved

Glide.with(holder.itemView.getContext()) .load(listPresident.get(position).getPhoto()) .apply(new RequestOptions().override(55, 55)) .into(holder.imgPhoto);

thanks you

iiibnuadam avatar Jun 19 '19 02:06 iiibnuadam

goto link: https://github.com/bumptech/glide/issues/1104

ali20kp avatar Aug 24 '20 08:08 ali20kp