Home » Android » android – Clearing Picasso images cache

android – Clearing Picasso images cache

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am using the Picasso library on my Android app to load images. I would like to add an option called “Clear images cache” on my app that would remove all the downloaded images from the cache, but obviously that would remove the downloaded images from my app only (I mean not from the other apps).

Is there a simple way to do that using Picasso? Using a native component?

Thanks!

How to&Answers:

You can clear in-memory cache in Picasso only per image:

Picasso.with(context).invalidate(imagePath);

Removing all cache is somewhat tricky and described here.

File cache is delegated to HTTP Client, so it’s not possible to clear it from Picasso. For more information refer this answer.

Answer:

Try this line of code given below, this removes the resource inside ImageView.

Picasso.with(context).setImageResource(0);