gonzalomelov
gonzalomelov

Reputation: 981

Picasso not pre-fetching image

I'm pre-fetching an image using Picasso and it is not being cached. The calls are:

In a previous activity I have:

Picasso.with(this)
  .load(uri)
  .fetch();

And in the next activity I have:

Picasso.with(this)
  .load(uri)
  .fit()
  .centerInside()
  .placeholder(R.drawable.placeholder)
  .error(R.drawable.error)
  .into(profileImage, null);

What maybe happening?

Upvotes: 0

Views: 277

Answers (1)

alfco333
alfco333

Reputation: 11

I had the same problem, a few weeks ago, the thing is, that when you fetch the image with this code:

    Picasso.with(this)
      .load(uri)
      .fetch();

Picasso saves the image in cache using the url as the key (the original image is saved in your disk/ram), but when the you try to present the image using the .into() method, the key that is generated by Picasso it's in fact different, because it includes the size of the imageView that it's going to hold the downloaded image. So if you want to really to put in cache the exact image you will need, you must include the resize method in your fetch call (this size must be the same of your imageView), e.g.

    Picasso.with(context).load(imageUrl)
    .resize(targetWidth,targetHeight)
    .fetch();

Upvotes: 1

Related Questions