Here's a critical point I don't know concerning the behavior of Picasso.
Imagine you are, say, showing a slide-show of ten items. Say, they are on-screen for ten seconds each.
The ideal behavior would be this: at the start of the slide show, I simply perform following:
picasso.get( url1 )
picasso.get( url2 )
picasso.get( url3 )
picasso.get( url4 )
picasso.get( url5 )
picasso.get( url6 )
picasso.get( url7 )
picasso.get( url8 )
picasso.get( url9 )
picasso.get( url10 )
And, in fact, Picasso would do those one at a time, in a queue.
What is the behavior of Picasso, if I tell it to pre-warm 10 urls all at once?
Is it possible to have Picasso do things only one at a time, in order - is there such an option?
(Other questions arising are, can you cancel the queue, or ...?)
thanks to an amazing answer @alicanozkara on this page I learned for the first time about
https://github.com/facebook/fresco
(13k stars) for better or worse I think the Picasso era is probably over.
Using only Picasso
, what I think you can achieve is:
1) Load all the images asynchronously in the cache using fetch()
like so:
Picasso.with(context).load(URL).fetch();
You can also add priority for images you want to load early: (Maybe mention high priority for first few images of the slide)
Picasso.with(context)
.load(URL)
.priority(Picasso.Priority.HIGH) // Default priority is medium
.fetch();
2) About cancelling the queue, you can add a common tag()
to your images and you can pause/cancel/resume anytime!
private static final Object TAG_OBJECT = Object();
Picasso.with(context)
.load(URL)
.tag(TAG_OBJECT)
// can be any Java object, must be the same object for all requests you want to control together.
Then we can control the tag like so:
Picasso.with(context)
.pauseTag(TAG_OBJECT)
//.resumeTag(TAG_OBJECT)
//.cancelTag(TAG_OBJECT)
3) Another important thing I would like to suggest is when you are pre-loading your images, only save them into your disk-cache, and load them to your memory-cache only while displaying. It will prevent flushing other important images from the memory-cache:
Picasso
.with(context)
.load(URL)
.memoryPolicy(MemoryPolicy.NO_STORE) //Skips storing the final result into memory cache.
.fetch()
4) For sequentially loading your images in a queue, you can pass your own ExecutorService
(SingleThreadExecutor
in your case) using executor(ExecutorService)
method, present in Picasso.Builder
You can even change the size of disk cache by using downloader(Downloader)
method and your memory cache using memoryCache(Cache)
method, both found in Picasso.Builder
class.
Other Awesome Libraries: