Skip to content Skip to sidebar Skip to footer

How To Clear Data Cache Of The Application Through Code

i want to clear data cache programmatic of my application that is increasing, right now i am clearing from Settings->Applications->Manage Application->My Application->C

Solution 1:

When you calling this class, it`ll calculate all installed application cache files and then simply delete it from your phone, which are not affected to database or your personal data. it will boost your phone and make it faster, cache file is removed

publicclassMyApplicationClassextendsApplication {

    privatestaticMyApplicationClass instance;

    @OverridepublicvoidonCreate() 
    {
        super.onCreate();
        instance = this;
    }

    publicstaticMyApplicationgetInstance() {
        return instance;
    }

    publicvoidclearApplicationData() {
        File cache = getCacheDir();
        File appDir = newFile(cache.getParent());
        if (appDir.exists()) {
            String[] children = appDir.list();
            for (String s : children) {
                if (!s.equals("lib")) {
                    deleteDir(newFile(appDir, s));
                    Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
                }
            }
        }
    }

    publicstaticbooleandeleteDir(File dir) {
        if (dir != null && dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(newFile(dir, children[i]));
                if (!success) {
                    returnfalse;
                }
            }
        }

        return dir.delete();
    }
}

Solution 2:

Just a guess:

Delete these files by knowing their absolute path to cache directory - getCacheDir() - http://d.android.com/reference/android/content/Context.html#getCacheDir().

Post a Comment for "How To Clear Data Cache Of The Application Through Code"