1

I'm currently working on a slideshow-app which displays multiple images with animation in a own implementation of ImageSwitcher. Before the ImageSwitcher gets displayed, I preload (cache) the images with Picasso with fetch().

The following method will be called when the next image should load:

public void setImageSource(final String url) {
    final ImageView image = (ImageView) this.getNextView();
    image.setVisibility(View.VISIBLE);

    BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
    if (drawable != null && drawable.getBitmap() != null) {
        drawable.getBitmap().recycle();
    }

    PicassoUtils.getPicassoWithBasicAuthorizationFrom(user, getContext())
            .load(url)
            .noFade()
            .fit()
            .centerCrop()
            .into(image);

    showNext();
}

The image.setVisibility(View.VISIBLE) is needed to make picasso able to read the dimensions of the ImageView. And the recycling is needed to save memory, because when I do not do recycle the imageView the memory rises on every image switch.

But I have a big problem. The time between images is fixed and Picasso takes some time to load the image (even from the local cache) into the imageView, so I have a small delay.

The question is, how can I preload the next image?

PatrickMA
  • 887
  • 9
  • 23
  • Maybe I don't understood you, I have some problem with English, but why you not use AsyncTask to load next image (or two) in background after just switch it. While atleast one from the next bitmaps not loaded in background user have not to switch image. – Denis Sologub Dec 03 '15 at 10:16

0 Answers0