使用毕加索强制重新下载图像 [英] Force re-downloading image with Picasso

查看:85
本文介绍了使用毕加索强制重新下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,它将从特定的url下载图像并将其显示在ImageView上.服务器随时间更改此图像,但url保持不变.所以我想实现这样的逻辑:

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:

  • 旋转或重新打开应用程序时,请从应用程序缓存中加载图片
  • 当用户单击下载按钮时,应从网络重新下载图像并替换缓存

如何用毕加索实现这种方法?也许其他一些库会更适合呢?

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

推荐答案

Picasso.with(context)
    .load(url)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .networkPolicy(NetworkPolicy.NO_CACHE)
    .fit()
    .centerCrop()
    .into(imageView);

每个NO_CACHE在向下加载资源时跳过高速缓存.缓存的版本将通过新内容进行更新.

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

这篇关于使用毕加索强制重新下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆