相关疑难解决方法(0)

以编程方式在Android应用中清除缓存

什么是以编程方式清除android应用程序中的缓存的正确方法.我已经使用了以下代码,但它看起来不适合我

@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 …
Run Code Online (Sandbox Code Playgroud)

android

57
推荐指数
5
解决办法
9万
查看次数

标签 统计

android ×1