图像在 ImageView 中没有改变

Image not changing in ImageView

我正在 android 中制作图像加载演示,我先使用了 UniversalImageLoader 然后 picasso 然后 ImageLoader class,但是所有有时当我将新图像上传到服务器并成功上传到服务器时,当我试图将其设置为 ImageView 时,之前加载的图像保持不变,它没有改变,我对此感到非常沮丧和浪费2天来解决这个问题,没有运气,请帮助我挽救我的生命。

我的代码如下:

Picasso.with(getApplicationContext())
            .load(Pref.getValue(getApplicationContext(),
                    Const.PREF_PROFILE_PIC, "")).into(iv_profile);

    Picasso.with(getApplicationContext())
            .load(Pref.getValue(getApplicationContext(),
                    Const.PREF_COVER_PIC, "")).into(iv_cover);

尝试在 url 的末尾添加一个 cachebreaker:

String imageurl1 = Const.PREF_PROFILE_PIC + "?" + new Date().getTime();
String imageurl2 = Const.PREF_COVER_PIC + "?" + new Date().getTime();

Picasso.with(getApplicationContext())
        .load(Pref.getValue(getApplicationContext(),
                imageurl1, "")).into(iv_profile);

Picasso.with(getApplicationContext())
        .load(Pref.getValue(getApplicationContext(),
                imageurl2, "")).into(iv_cover);

这会在您创建图像时自动附加当前时间戳,它会让浏览器再次查找图像,而不是从缓存中检索图像。

思路同上。但它对我不起作用。

我得到了答案 link

如下所示更改您的 URL:

String imageurl = url + "?time=" + System.currentTimeMillis();
Picasso.with(getContext()).load(imageurl).into(imageView);

这对我有用。谢谢