Android App Development With AndroidCource: clear cache in adroid
Showing posts with label clear cache in adroid. Show all posts
Showing posts with label clear cache in adroid. Show all posts

Saturday, 7 July 2018

How to Clear Cache Data in Android Application Programmatically

How to Clear Cache in your Android Application.And How to Delete/Clear Cache in android with programmatically.in this example to how to delete cache in in this example cache clear when click button to delete application cache in android programmatically.


 public static void deleteCache(Context context) {
        try {
            File dir = context.getCacheDir();
            deleteDir(dir);
        } catch (Exception e) {}
    }
    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();
        } else if(dir!= null && dir.isFile()) {
            return dir.delete();
        } else {
            return false;
        }
    }

In this method to call button click event and run your application to press button to clear all cache in your application to programmatically.



Ads