Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Universal Image Loader requests with same URL are being cancelled

I am trying to load images to the bitmaps using UIL. I need to load multiple images and I have noticed that in some cases image urls can be the same. And in such cases only first image is loaded. How to avoid request cancelling in UIL?

Code is run 3 times in the loop:

ImageSize targetSize = new ImageSize(70, 70);
ImageLoader.getInstance().loadImage("http://icons.iconarchive.com/icons/yellowicon/game-stars/256/Mario-icon.png", targetSize, new ImageLoadingListener() {
    @Override
    public void onLoadingStarted(String imageUri, View view) {
        Log.e("tag", "onLoadingStarted");
    }

    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
         Log.e("tag", "onLoadingFailed");
    }

    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        Log.e("tag", "onLoadingComplete");
    }

    @Override
    public void onLoadingCancelled(String imageUri, View view) {
        Log.e("tag", "onLoadingCancelled");
    }
});

Logs are:

onLoadingStarted
onLoadingStarted
onLoadingStarted
onLoadingComplete
onLoadingCancelled
onLoadingCancelled
like image 380
Vadims Savjolovs Avatar asked Nov 18 '14 19:11

Vadims Savjolovs


1 Answers

UIL cancels previous displayImage(...) task for the same ImageView.

UIL cancels previous loadImage(...) task for the same URL.

Actually for both cases UIL operates with ImageAwares inside and compare ImageAware.getId() to decide to cancel task or not.

In your case to prevent task cancelling you can do like this:

ImageSize targetSize = new ImageSize(70, 70);
ImageAware imageAware = new NonViewAware(targetSize, ViewScaleType.CROP);
ImageLoader.getInstance().displayImage("http://icons...", imageAware, ...);
like image 167
nostra13 Avatar answered Oct 16 '22 15:10

nostra13