1

I have activity in which there is a dialog window with some images. I want to download these images into cache when my activity starts and load them from cache when dialog window appears.

My activity code:

for(int i=0; i<avataritemlist.size();i++){

                Picasso.with(activity_context)
                        .load(item.getpath())
                        .noFade();

            }

Dialog adapter code:

Picasso.with(mContext)
            .load(item.getpath())
            .noFade()
            .into(holder.imageView);

I expect to cache the image in my activty and then in dialog adapter load in from cache, but in my case it downloads it again in adapter. I want to emphasize that activity_context and mContext is the same. What am I doing wrong?

Taldakus
  • 705
  • 2
  • 8
  • 18
  • Use ImageLoader which will help to maintain cache and load images from cache for more info refer : http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
    https://developer.android.com/training/volley/request.html
    – Shadow Droid Sep 13 '15 at 11:09
  • But it is for volley library, I am using Picasso – Taldakus Sep 13 '15 at 11:13
  • sorry my mistake for posting one link...I have added a link on cachin image as well... – Shadow Droid Sep 13 '15 at 11:21

1 Answers1

0

Default Picasso instance returned by Picasso.with uses an automatic memory and disk caching. It is initialized with default values:

 •  LRU memory cache of 15% the available application RAM   

 •  Disk cache of 2% storage space up to 50MB but no less than 5MB. (Note: this is only available on API 14+ or if you are using a standalone library that provides a disk cache on all API levels like OkHttp)

 •  Three download threads for disk and network access.

How default Picasso instance does LRU memory cache is something you might not be able to know, all you know is it is a memory cache which uses a least-recently used eviction policy.

However you can create a Picasso instance using Picasso.Builder that gives you a better control over image caching (over disk). Check more on this stackoverflow post on how to set up http request header property Cache-Control with max-age and Jake Wharton's answer too

Also you may also want to try out Glide which syntactically is very similar to Picasso

Community
  • 1
  • 1
random
  • 10,238
  • 8
  • 57
  • 101