question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't call onCancel for prefetched RecyclerView items.

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
colinrtwhitecommented, Oct 7, 2020

@clhols The issue is if the request is started on a detached view in a Fragment (like with RecyclerView prefetch) it’ll never have onViewDetachedFromWindow called, which can leak the containing Fragment. 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!

0reactions
colinrtwhitecommented, Mar 7, 2022

This is fixed in 2.0.0-rc01.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recyclerview not call onCreateViewHolder - Stack Overflow
Another cause of this problem is mistakenly making the item layout match the height of the parent, so only one item is shown...
Read more >
RecyclerView - Android Developers
Adapter: A subclass of Adapter responsible for providing views that represent items in a data set. Position: The position of a data item...
Read more >
RecyclerView Prefetch. Smoother Flings and Scrolls by Doing…
During a scroll or fling operation, RecyclerView will need to display new items as they arrive on screen. These new items need to...
Read more >
Using the RecyclerView | CodePath Android Cliffnotes
Java; Kotlin. // do not reinitialize an existing reference used by an adapter contacts = Contact ...
Read more >
Recyclerview Pro Tips — Part 1 - ProAndroidDev
Set setHasFixedSize attribute recyclerView.setHasFixedSize(true) when the recycler view item do not change sizes of its children at runtime.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found