Force re-downloading image with Picasso

2019-05-07 17:18发布

I'm creating an application which is going to download image from specific url and display it on ImageView. Server changes this image over time, but url stays the same. So I want to implement such logic:

  • When app is rotated or reopened, load image from apps cache
  • When user clicks the download button, image should be re-downloaded from the network and replace the cache

How do I implement such approach with Picasso? Or maybe some other library would fit it better?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-05-07 17:31
Picasso.with(context)
    .load(url)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .networkPolicy(NetworkPolicy.NO_CACHE)
    .fit()
    .centerCrop()
    .into(imageView);

Each NO_CACHE skips the cache on the way down to load the resource. The cached version will be updated by the new content.

查看更多
登录 后发表回答