4

I am using picasso library in my project to fetch url images from the server into my ImageView, but unfortunately picasso loading the previously cached images from disc instead of loading the new images from url. Please find the below piece of code for your reference.

Picasso.with (ImageActivity.this)
                    .load(url)
                    .placeholder (R.drawable.default_user)
                    .error (R.drawable.default_user)
                    .into(imgUser);

I have also tried the solutions like:

Picasso.with(ImageActivity.this).invalidate(url);

and

Picasso.with (ImageActivity.this)
                            .load(url).memoryPolicy(MemoryPolicy.NO_CACHE)
                            .placeholder (R.drawable.default_user)
                            .error (R.drawable.default_user)
                            .into(imgUser);

But nothing is working for me. Kindly help me to resolve my issues.

Thanks in advance.

Community
  • 1
  • 1
Chandru
  • 5,954
  • 11
  • 45
  • 85

2 Answers2

21

Try :

  Picasso.with(mContext)
        .load(URL)
        .memoryPolicy(MemoryPolicy.NO_CACHE )
        .networkPolicy(NetworkPolicy.NO_CACHE)
        .error(R.drawable.xxx)
        .into(xx);
Nikhil Verma
  • 1,777
  • 1
  • 20
  • 41
  • 1
    Is there a Solution for exact inverse of it. I want to load images only from Cache even if there is Connection. Because I wan't to have a Settings that disables Image Loading to save data – Y2K Jul 27 '15 at 06:48
-1

I know there's already an answer but after trying a few ways I figured out a very simple way: Check if the image is null - if it is not - then load the image with Picasso-like that:

if(vImage.getDrawable() == null)
Picasso.with(context).load(URL).into(vImage);

Hope this helped someone.

Noy
  • 116
  • 1
  • 10