In my app because I use Bitmap factory to get bitmap image object from http url lot of data is getting cached. So i wrote following code to clear cache data everytime application loads. Its similar to what we do manually by clicking Clear Cache button in Setting -> Apps -> YOUR_APP.
However following code i wrote is not working. Cache size is as it is.
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") && !s.equals("shared_prefs")) {
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();
}
I also added following permission in AndroidManifest.xml of my application:
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
Please help. And how we use Bitmap factory in efficient way to reduce performance and improve efficiency.
0 comments:
Post a Comment