Getting Picasso to pre-fetch forthcoming images

DaBeeeenster picture DaBeeeenster · Jul 22, 2014 · Viewed 8.8k times · Source

I'm using Picasso with a GridView, loading 200 images over the network. Right now it looks like Picasso is not triggering an image load over the network until the image starts to come into view on the screen.

Is there a way to have Picasso pre-fetch the next N images in the list so that the experience is better? I am using an Adapter to put the images into the Gridview.

Answer

Bill Mote picture Bill Mote · Aug 1, 2014

I am prefetching images into a cache very successfully using Picasso like so:

if (BuildConfig.DEBUG) {
     Picasso.with(getApplicationContext()).setIndicatorsEnabled(true);
     Picasso.with(getApplicationContext()).setLoggingEnabled(true);
}
for (Article article : articleList) {
     ArrayList<String> images = article.getImages();
     for (String url : images) {
          if (!TextUtils.isEmpty(url)) {
               Picasso.with(getApplicationContext())
                    .load(url)
                    .resizeDimen(R.dimen.article_image_preview_width, R.dimen.article_image_preview_height)
                    .centerCrop()
                    .fetch();
          }
     }
}