Stillie
Stillie

Reputation: 2676

Cache Images with Volley

I'm trying to implement Image Caching into my app. The code i currently have regarding the images is below:

Network call to get images:

public void getImage(String url, final ImageView imageView) {

    System.out.println("Image Url is: " + url);
    ImageRequest requestImage = new ImageRequest(url, new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            imageView.setImageBitmap(response);
        }
    }, 0, 0, null, null);

    queue.add(requestImage);
}

How could I implement the caching? I have read a few articles on SO, but am not sure on how to implement it into my app?

Thanks for your help

Upvotes: 1

Views: 89

Answers (2)

hata
hata

Reputation: 12478

  1. You have better use ImageLoader instead of using ImageRequest directly.
  2. When you instantiate an ImageLoader object, you set an ImageCache object. (That is what you want, isn't it?)

Volley's ImageLoader uses internally ImageRequest convined with ImageCache.

Upvotes: 2

Jai
Jai

Reputation: 1984

I think you should try this one of the best image caching library :

https://github.com/loopj/android-smart-image-view

Upvotes: 0

Related Questions