2

I built an android application on the android studio to get the feedback of customers, and at the beginning of each activity, I put a voice over.. When the customer finishes the task, the application returns to the first screen (activity 1).

I want to clear the cache of the application when it arrives at the last activity to avoid cache problems (lack of sound..etc)

Thanks a lot

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

2

to delete cache of your own application then simply delete your cache directory

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

and it won't clear your shared preference.

Thank you....

Vijaya Varma Lanke
  • 603
  • 2
  • 7
  • 19