Android-Universal-Image-Loader
Android-Universal-Image-Loader copied to clipboard
Loading the same url into different views simultaneously
I have to update several image views with the same url, when I get an update event. The code does something like:
imageLoader.loadImage(url, targetSize, opt, new SimpleImageLoadingListener() {
public void onLoadingComplete(String url, View view, Bitmap loadedImage) {
... some accounting goes here ...
view.setImageBitmap(bitmap);
}
public void onLoadingCancelled(String url, View view) {
Log.w("Loader", "onLoadingCancelled");
}
})
This is called with the same url on different views. As a result, none of the views gets updated - onLoadingCancelled is called on all instances.
If I add to the url a random argument (url + "&xxx=" + rnd()), everything goes as planned. I suspect a caching problem, but can't be sure.
I traced the problem down to the way isViewReused() is implemented. It calls engine.getLoadingUriForView(imageAware) to get the cache key. This depends on the imageAware's id, which is derived from the uri (for NonViewAware) or the view's hashCode (for ViewAware).
The problem with loadImage (contrary to displayImage) is that it uses the same id for different load tasks on different views, causing a caching clash.
One solution is to use displayImage instead, but that's not exactly what I want. Another solution would be to add a unique [optional] "taskId" to the loadImage method, and to add it to the NonViewAware
Maybe it could help you: https://mp.weixin.qq.com/s/dFdKg5CDVUXktQiE9p9Kcg
I'm not clicking that link...