简体   繁体   中英

android picasso Image dowloading

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM