In Android 4.0 I use this solution to clear my application cache and it works perfectly:
public void clearApplicationData()
{
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if (appDir.exists()) {
String[] children = appDir.list();
for (String s : children) {
if (!s.equals("lib")) {
deleteDir(new File(appDir, s));
}
}
}
}
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();
}
Unfortunately, this solution doesn't work in 4.2.2 Android version (and probably in above Android versions too). Anybody knows why? Maybe there is another method to clear cache?
Particulary I am interested in google map cache clearing and solution written above works for me in Android 4.0 but not in Android 4.2.2. Any help would be appreciated.
I don't get any errors in logcat. Device: Samsung Galaxy Tab 2 7.0'