清除高速缓存中的Andr​​oid应用程序编程 [英] Clearing Cache in android App Programmatically

查看:141
本文介绍了清除高速缓存中的Andr​​oid应用程序编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要关于我的Andr​​oid应用程序缓存一扶。我在设备运行的服务器(机器人)。我想这样做,应用程序清除缓存编程。我有数据库在该服务器。基于该数据库上我的客户操作正在进行。所以,我不希望它(数据库)得到实现。我只是要清除高速缓存不清除数据。请帮我这一点。

I need one help regarding cache memory in my android app. I am Running server (android) in a device. I want to do clear cache of that app programmatically. I have database in that server. Based on that database my client operations are going on. So I don't want it (Database) to get effected. I just want to clear cache not to clear data. Please help me with this.

推荐答案

code清除缓存:

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            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();
    }
    return false;
}

这篇关于清除高速缓存中的Andr​​oid应用程序编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆