惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
有赞技术团队
有赞技术团队
量子位
N
Netflix TechBlog - Medium
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
V2EX
IT之家
IT之家
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - ganzhijie

Glide将网络图片压缩成指定大小并保存到本地 Android加固之后Apk重签名 Mac显示和隐藏“隐藏文件”命令 Android Installation failed with message INSTALL_FAILED_TEST_ONLY Could not find any version that matches com.android.support:appcompat-v7:30.+.的解决步骤 ndk{abiFilters:}的使用 Android Studio解决support-annotations版本冲突 解决javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.的问题 如何查看手机cpu是32位还是64位 Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法 DialogFragment异常Fragment already added的原因与解决办法 查看apk安装包的AndroidManifest.xml文件 ListView中动态显示和隐藏Header&Footer Android动画效果translate、scale、alpha、rotate Android手机主流屏幕分辨率有哪些? OPhone中的图片特效处理 Android手势(上,下,左和右的判断) Android UI秘笈:谨记该做什么不该做什么 Android permission 访问权限大全
清除应用缓存
ganzhijie · 2026-04-13 · via 博客园 - ganzhijie

清除应用缓存

try {
    // 获取应用的缓存目录
    File dir = getApplicationContext().getCacheDir();
    // 删除缓存目录中的所有文件
    deleteDir(dir);
} catch (Exception e) {
    e.printStackTrace();
}

private 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){
        return dir.delete();
    } else {
        return false;
    }
}

posted @ 2026-04-13 21:55  ganzhijie  阅读(5)  评论(0)    收藏  举报