在Android应用程序清除缓存编程

什么是明确的Andr​​oid应用程序缓存编程的正确方法。我已经使用以下code,但它不是找我的工作

what is the correct way to clear cache in android Application programmatically. I already using following code but its not look work for me

@Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        clearApplicationData();
}
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));
        Log.i("EEEEEERRRRRRROOOOOOORRRR", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
        }
        }
        }
        }

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



 1 条回答