Don't call onCancel for prefetched RecyclerView items.
See original GitHub issueHi,
I am using ImageRequest.Listener
to control a loading spinner in a custom ImageView
on Android.
The purpose of the loading spinner is (if it’s not obvious) to be shown when the request is in progress and before the image is loaded from a server.
I was using both onSuccess()
, onCancel()
and onError()
to hide the loading spinner, because whenever the request was cancelled for some reason, or when an error occurred, I don’t want to show a loading spinner, but just default back to showing a placeholder image.
However, after upgrading to version 1.0.0-rc3, it seems that onCancel()
is being fired by the library immediately. This has changed from previous versions. I thought it could have something to do with images being available in cache, but I just did a test where I cleared memory and disk cache, and onCancel()
was still being fired immediately.
What has changed, what is the cause of onCancel()
being fired in the first place?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
@clhols The issue is if the request is started on a detached view in a
Fragment
(like withRecyclerView
prefetch) it’ll never haveonViewDetachedFromWindow
called, which can leak the containingFragment
. We need to cancel the request instantly if it’s started on a detached view (I believe Glide errors in this case) to guard against this case. If the view is attached, the request will automatically restart.Ideally, we would handle
RecyclerView
prefetch more gracefully and not cancel then restart the request. Open to ideas!This is fixed in
2.0.0-rc01
.