Canceling Android Image Request Based on Progress - Volley Image Downloader, Picasso

Github has many popular graphical downloaders for loading and caching images and managing image retrieval.

I ran into a requirement, if Imageview , if no longer bound to the window, the request (package and flight) will be canceled.

However, a scrollable widget like Listview and Gridview Imageview is often attached and detached from the window, so the queued request is canceled accordingly.

My concern is that they don't have a mechanism to track the progress of an image request across the entire library above. If the Imageview is detached , the request should be canceled based on the progress, if the byte stream a was already done 75% of the work, then it should not be canceled, which in turn will reduce the network bandwidth and reduce the network call as usually the user is always a lot scrolls scrolling widget like Listview and Gridview etc.

Here's my understanding with Volley:

public boolean removeContainerAndCancelIfNecessary(ImageContainer container) {

    /* logic to check progress of Request */
    mContainers.remove(container);
    if (mContainers.size() == 0) {

        mRequest.cancel();
        return true;
    }
    return false;
}

      

Here is my understanding with Picasso:

private void cancelExistingRequest(Object target) {

    checkMain();
    Action action = targetToAction.remove(target);
    if (action != null) {

        action.cancel();
        dispatcher.dispatchCancel(action);
    }
    if (target instanceof ImageView) {

        ImageView targetImageView = (ImageView) target;
        DeferredRequestCreator deferredRequestCreator = targetToDeferredRequestCreator.remove(targetImageView);
        if (deferredRequestCreator != null) {

            deferredRequestCreator.cancel();
        }
    }
}

      

Here is my understanding with the Universal Image Loader: I have not seen that the universal image loader allows you to override an inline request.

void cancelDisplayTaskFor(ImageAware imageAware) {

    cacheKeysForImageAwares.remove(imageAware.getId());
} 

      

Please let me know if it is possible to solve this problem for network request only. If the image has already been cached, we will cancel the request.

Battery performance really matters in Android

+3


source to share


1 answer


I can't tell you about Volley and Picasso, but I can tell you how UIL works.

The UIL constantly checks the ImageView while processing a task. If the task becomes inactive (the ImageView is being recycled (reused) or collected by the GC), then the UIL stops the task for that ImageView.



How about the image becomes inactive on upload? UIL cancels loading if less than 75% of image data is loaded. If more than 75%, then UIL completes the download (that is, UIL caches the image file in the disk cache) and then cancels the task.

+2


source







All Articles