Picassoを使用して画像を表示しています。必要なときにキャッシュを強制的にクリアすることはできますか? 私はそれをグーグルで検索しましたが、解決策が見つかりません。
ありがとうございました。
このコードを使用
import java.io.File;
import android.content.Context;
import com.androlizer.yify.torrent.R;
public class ClearCache {
public static void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
if (deleteDir(dir)) {
CreateSuperToast.createInfoToast(context, context.getString(R.string.cache_cleared));
}else{
CreateSuperToast.createInfoToast(context, context.getString(R.string.cache_not_cleared));
}
}
} catch (Exception e) {
// TODO: handle exception
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
}