Android-Universal-Image-Loader icon indicating copy to clipboard operation
Android-Universal-Image-Loader copied to clipboard

Loading the same url into different views simultaneously

Open grebulon opened this issue 9 years ago • 3 comments

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.

grebulon avatar Feb 08 '16 11:02 grebulon

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

grebulon avatar Feb 10 '16 10:02 grebulon

Maybe it could help you: https://mp.weixin.qq.com/s/dFdKg5CDVUXktQiE9p9Kcg

PoetKing avatar Jan 31 '18 07:01 PoetKing

I'm not clicking that link...

grebulon avatar Jan 31 '18 07:01 grebulon