开发者

clear cache mwmory when will i start my application in android

开发者 https://www.devze.com 2023-01-14 18:21 出处:网络
I want to program for clear cache memory when will i start my application in android,Anybody开发者_高级运维 knows coding please give me.

I want to program for clear cache memory when will i start my application in android,Anybody开发者_高级运维 knows coding please give me.

Thanks All


try this

public static void trimCache(Context context) {
        try {
            File dir = context.getCacheDir();
            if (dir != null && dir.isDirectory()) {
                deleteDir(dir);

            }
        } catch (Exception e) {
            // TODO: handle exception
        }

    }

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

        // The directory is now empty so delete it
        return dir.delete();
    }

and also add this line in your menifest.xml

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"></uses-permission>
0

精彩评论

暂无评论...
验证码 换一张
取 消