0

I have to create a new image based on Bitmap on the cache of my application, this works fine but when i have to create another one this process of creating and delete works to, but the image showed on the screen is still the first image i created.

Android saves the image on memory or what?

E. Greeff
  • 359
  • 1
  • 11

1 Answers1

0

I find a solution for this question, but idk if it's the correct solution

If i delete the cache DIR it work's fine, deleting only the image don't work

This code from: https://stackoverflow.com/a/23908638/10034413

public static void deleteCache(Context context) {
try {
    File dir = context.getCacheDir();
    deleteDir(dir);
} catch (Exception e) { e.printStackTrace();}
}

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;
            }
        }
        return dir.delete();
    } else if(dir!= null && dir.isFile()) {
        return dir.delete();
    } else {
        return false;
    }
}
E. Greeff
  • 359
  • 1
  • 11