You cannot start a load for a destroyed activity
My glide version:
compile 'com.github.bumptech.glide:glide:3.7.0'
Exception info
java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:134)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:102)
at com.bumptech.glide.Glide.with(Glide.java:653)
Yes? You cannot start a load for a destroyed activity. There's no better way of saying it. If the activity is destroyed it won't ever be visible again, the user can't see your image, so there's no point in even trying to start to download it. See #803 for more discussion.
Getting Same Problem.
.... crash , why not log ?
Same problem. Why is it a crash and not just log message?
I got the same problem, how to stop this crash? i am using gradle 'com.github.bumptech.glide:glide:3.7.0'
Hi @all. the problem occurs most when your activity is recreated and the context that's in Glide is an old one. for instance when you have a CustomAdapter(ArrayList list, Context context), and in MainActivity or Fragment recreation, you're not passing the new context to the adapter. Glide then tells you that the context i'm using does no more exist. I hope you understood that. whoever needs a debug can invite me to contribute in his project.
What is a workaround for this issue?
I fixed this by using getApplicationContext()
It's dangerous to load images with App context, they won't be recycled when the activity dies Le 6 avr. 2017 1:06 PM, "Darran Kelinske" [email protected] a écrit :
I fixed this by using getApplicationContext()
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bumptech/glide/issues/1484#issuecomment-292153414, or mute the thread https://github.com/notifications/unsubscribe-auth/ALgcboB-HlC_FBnE4WWtId558DxkzoCBks5rtNUkgaJpZM4KGRnN .
Can you please provide an effective alternative then?
Guys, read the duplicate issue; particularly: Dec 10-14.
That looks like a better workaround than app-context, especially in @neonwarge04's case (why did you remove your comment? [it was about cancelling retrofit calls, but still getting the crash])
Will check it out. Thank you! :)
Got the same issue today when using version compiled into FirebaseUI v.2.0.1. I was scrolling my recyclerview and error occurs.
It can be fix by using:
if (!YourActivity.this.isFinishing()) {
Glide.with(...
}
I fixed this using getApplicationContext() while initializing the glide as Glide.with(getApplicationContext()) and pause all request by overriding onDestroy() as @Override protected void onDestroy() { super.onDestroy(); Glide.with(getApplicationContext()).pauseRequests(); }
taranjeetspra, it will blocking pause all Glide requests - if you use a service that fires notifications and it uses Glide for the avatar - it will block the notification.
@targetapi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static boolean isActivityDestroyed(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity != null && activity.isDestroyed()) { return true; } return false; }
when you load image in Activity, please check like this. If the activity isDestroyed, stop load image by Glide, else load image by Glide
@meikaiss I tried doing what you did but I am still seeing the issue
I am using following util function before loading any image
final Context context = getContext();
if (isValidContextForGlide(context) {
// Load image via Glide lib using context
}
public static boolean isValidContextForGlide(final Context context) {
if (context == null) {
return false;
}
if (context instanceof Activity) {
final Activity activity = (Activity) context;
if (activity.isDestroyed() || activity.isFinishing()) {
return false;
}
}
return true;
}
Code Ref:
- https://github.com/bumptech/glide/blob/99229725401d5777e059da7b6331134bf73fbcdf/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java#L321
@farhan yup, that's what i had to end up doing. should have updated it here.