清除缓存应用程序不起作用

时间:2013-07-13 05:47:03

标签: java android xml

我想让我的应用程序能够直接从应用程序本身清除缓存,而无需进入设置。在Stack Overflow上寻找我发现这个片段,但它有很多错误。你能帮我解决一下吗?

Preference cache;
cache = (Preference) this.findPreference("cache");
cache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
     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("TAG", "**************** 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();

}

eclipse标记错误此处文件appDir = new File(cache.getParent());, here},这里是public static boolean deleteDir(File dir),这里是if(dir!= null&amp;&amp; dir.isDirectory( )){

0 个答案:

没有答案