Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Shakezulla57 opened this issue Dec 6, 2017 · 6 comments
Closed

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

Shakezulla57 opened this issue Dec 6, 2017 · 6 comments

Comments

@Shakezulla57
Copy link

Shakezulla57 commented Dec 6, 2017

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)
@sjudd
Copy link
Collaborator

sjudd commented Dec 6, 2017

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 sjudd added the question label Dec 6, 2017
@Shakezulla57
Copy link
Author

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.

@sjudd
Copy link
Collaborator

sjudd commented Dec 7, 2017

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

Then just requestManager.clear(imageView) is fine.

@stale
Copy link

stale bot commented Dec 14, 2017

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 stale bot added the stale label Dec 14, 2017
@stale stale bot closed this as completed Dec 21, 2017
@iiibnuadam
Copy link

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

@ali20kp
Copy link

ali20kp commented Aug 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants