我正在用android作imageLoading演示,我先使用了UniversalImageLoader然后使用picasso然后使用了ImageLoader类,但是每次我将新图像上载到服务器并成功上载到服务器时以及尝试将其设置为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);

最佳答案

尝试在网址末尾添加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);


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

07-28 01:12
查看更多