glide
glide copied to clipboard
If the same URL is read into the View, the RequestListener will be reused as stale.
As of Glide 4.16.0, stale instances of RequestListener are reused.
It is common to load images into a single ImageView with Glide. A new RequestListener should be used for each call to Glide, even if it is the same URL.
Up until Glide 4.15.1, newly created listeners are called, but starting in 4.16.0, old listener instances are called.
private fun loadImage(url: String) {
val listener = object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
Log.d("TAG", "[onLoadFailed] = ${hashCode()}")
return false
}
override fun onResourceReady(
resource: Drawable,
model: Any,
target: Target<Drawable>,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
Log.d("TAG", "[onResourceReady] = ${hashCode()}")
return false
}
}
Log.d("TAG", "[Listener] = ${listener.hashCode()} ==> $url")
Glide.with(binding.imgView)
.load(url)
.centerCrop()
.addListener(listener)
.into(binding.imgView)
}
Demo project
- sample : https://github.com/Pluu/GlideListenerBugSample
Glide 4.15.1
Glide 4.16.0
8f6d64519574c9a199f96269f56fae8ffb942b4f This commit fixes the code related to equals.
Previously, the comparison of localRequestOptions and otherLocalRequestOptions using equals behaved as RequestBuilder.equals, returning false when adding another Listener.
However, now it seems to have happened because the comparison of bothBaseRequestOptionsNullEquivalentOrEquals is done using the equals function, so it behaves the same as the equals function in BaseRequestOptions, so requestListeners returns true even if another Listener is added.
4.15.1
https://github.com/bumptech/glide/blob/facc541119ae523d0d489fe9a057dc1d2221afaa/library/src/main/java/com/bumptech/glide/request/SingleRequest.java#L773C2-L773C31
4.16.0
https://github.com/bumptech/glide/blob/3bbc3908edd8432f55ccfae3257bad533c1bf7d1/library/src/main/java/com/bumptech/glide/request/SingleRequest.java#L781
cc @mori-atsushi @sjudd @Pluu
我这边验证,4.15.0 4.15.1,4.14.2,都有这个问题,你确定4.15.1正常吗?