Closed
Description
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)
Activity
TWiStErRob commentedon Sep 26, 2016
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.
shivangbtech commentedon Oct 18, 2016
Getting Same Problem.
xiaojidonggong commentedon Dec 14, 2016
.... crash , why not log ?
AAverin commentedon Jan 9, 2017
Same problem. Why is it a crash and not just log message?
pankaj89 commentedon Jan 10, 2017
I got the same problem, how to stop this crash? i am using gradle 'com.github.bumptech.glide:glide:3.7.0'
steve111MV commentedon Jan 12, 2017
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.
Emeritus-DarranKelinske commentedon Mar 24, 2017
What is a workaround for this issue?
Emeritus-DarranKelinske commentedon Apr 6, 2017
I fixed this by using getApplicationContext()
steve111MV commentedon Apr 6, 2017
Emeritus-DarranKelinske commentedon Apr 6, 2017
Can you please provide an effective alternative then?
TWiStErRob commentedon Apr 6, 2017
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])
Emeritus-DarranKelinske commentedon Apr 7, 2017
Will check it out. Thank you! :)
23 remaining items
AhmadullahSaikat commentedon Feb 3, 2019
Please use
Glide.with(getApplicationContext())
instead ofGlide.with(this)
TWiStErRob commentedon Feb 3, 2019
Please don't use application context, use
Glide.with(this)
inonCreate
to get the best context for resource management and use dependency injection to pass theRequestManager
around. You don't even need to check for dying activities and stuff. See https://stackoverflow.com/a/32887693houchenl commentedon Aug 28, 2019
优化/修复 协程加载页面错误
优化/修复 协程加载页面错误
优化/修复 协程加载页面错误
优化/修复 协程加载页面错误
ali20kp commentedon Aug 24, 2020
goto link:
https://github.com/bumptech/glide/issues/1104
优化/修复 协程加载页面错误
rbenza commentedon Mar 17, 2022
I came up with this solution:
You then can simply call:
fun ImageView.loadUrl(url: String) = Glide.with(this).syncWithLifecycleOwner(this).into(this)
findViewTreeLifecycleOwner()
is present in AndroidX Lifecycle lib. It provides the Activity or the Fragment View's lifecycle this specific ImageView is attached to.See: https://stackoverflow.com/a/71503953/11310951
Prevent exception when activity is destroyed
Prevent exception when activity is destroyed
Prevent exception when activity is destroyed
Prevent exception when activity is destroyed