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

ImageAware is reused for another image. Task is cancelled.

Open pozuelog opened this issue 10 years ago • 3 comments

I'm trying to preload all needed images for offline using a service. I simply call load image. It works for most of images, nevertheless, sometimes I have a log: D/ImageLoader﹕ ImageAware is reused for another image. Task is cancelled. [http://lorempixel.com/400/200/abstract/1/_1280x800] And I receive an ImageCancelled callback.

This is my code, I'm not sure about what is happening here:

 Iterator<GdDocumentacion> iterator = docu.iterator();
        while (iterator.hasNext()) {
            ImageLoader imageLoader = ImageLoader.getInstance();
            DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).build();

            GdDocumentacion documentacion = (GdDocumentacion) iterator.next();
            final String imageUrl = documentacion.getImageUrl();

            imageLoader.loadImage(imageUrl, defaultOptions, new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    Log.d(TAG, "onLoadingStarted uri: " + imageUri);
                    List<Bitmap> cached = MemoryCacheUtils.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache());
                    Log.d(TAG, "onLoadingStarted cached isnull? " + (cached == null) + " y there are cached images: " + cached.size());
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    pendingImagesCounter --;
                    Log.w(TAG, "onLoadingFailed uri: " + imageUri + " pending images: " + pendingImagesCounter);
                    if(pendingImagesCounter<=0) onImageDownloadingFinished();
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    pendingImagesCounter --;
                    Log.d(TAG, "onLoadingComplete uri: " + imageUri + " quedan imágenes: " + pendingImagesCounter);
                    List<Bitmap> cached = MemoryCacheUtils.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache());
                    Log.d(TAG, "onLoadingComplete cached es null? " + (cached == null) + " y hay imágenes: " + cached.size());
                    if(pendingImagesCounter<=0) onImageDownloadingFinished();
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    Log.d(TAG, "onLoadingCancelled uri: " + imageUri);
                }
            });

pozuelog avatar Feb 24 '15 08:02 pozuelog

I have even simpler case but with the same result - Task is cancelled. I create 2 objects and each one calls 'fetchTwoImages' (see below), so totally it is supposed to be just 4 images (~120KB each) to download. I receive only one (!) and then that D/ImageLoader﹕ ImageAware is reused for another image. Task is cancelled... ImageLoader was initialized the way it is done in Sample code

Here is the code.


    public void fetchTwoImages() {

        ImageLoader.getInstance().loadImage(imageUrl1, new SimpleImageLoadingListener() {
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                Log.w(TAG, "bitmap1 loaded");
            }
        });

        ImageLoader.getInstance().loadImage(imageUrl2, new SimpleImageLoadingListener() {
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                Log.w(TAG, "bitmap2 loaded");
            }
        });
    }

nickfl avatar Feb 24 '15 16:02 nickfl

@nickfl @pozuelog Were you able to find a solution for this?

prat-z avatar May 09 '18 11:05 prat-z

You can implement your own ImageAware and define the getId method to download the image. e.g.

public class NonReusedViewAware implements ImageAware {
	@Override
	public int getId() {
		return super.hashCode();
	}
}
ImageLoader.getInstace().displayImage(URI,new NonReusedViewAware(),new ImageLoadingListener());

tangjingyuan avatar Jan 25 '19 08:01 tangjingyuan