Image not changing in ImageView

750 views Asked by At

I am making a demo in android for imageLoading, I have used first UniversalImageLoader then picasso and then an ImageLoader class,But all times when i upload a new image to server and it successful uploaded to server and when i am trying to set it to ImageView ,the previously loaded image is remains same,its not changing,I am so frustrated by this and wasted 2 days to solve this with no luck,Please help me to save my life.

my code is as below:

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);
2

There are 2 answers

4
Neerajlal K On BEST ANSWER

Try adding a cachebreaker at the end of the url:

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);

This will append the current timestamp automatically when you are creating the image, and it will make the browser look again for the image instead of retrieving the one in the cache.

0
Nabeel K On

the idea is same as above. but it didnt worked for me.

I got the answer from this link

change your URL as shown below:

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

this worked for me. thanks