-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Description
In Glide 4.16.0 I'm trying to cancel a load in response to a callback from a third party library.
The third party library is tracking the view lifecycle, and when the view is detached calls my callback to cancel any outstanding image loads. The view might be detached as part of the normal view lifecycle when it's a view managed by an adapter associated with a RecyclerView
and the user is scrolling, or it might be detached because the activity is ending.
The function (i.e., my code) it's calling looks like this:
override fun cancel(imageView: ImageView) {
Glide.with(imageView).clear(imageView)
}
That throws an undocumented IllegalArgumentException
because Glide.with
eventually calls this in RequestManagerRetriever.java
:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void assertNotDestroyed(@NonNull Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
}
}
This is misleading, as I am not trying to "start a load for a destroyed activity". At worst, calling .clear(imageView)
when the activity is destroyed should be a no-op.
Please document this exception. Please also consider pushing this assert to the .load()
methods, and/or only asserting in debug builds.