首页 > 系统 > Android > 正文

Android开发之删除项目缓存的方法

2019-10-24 20:24:15
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android开发之删除项目缓存的方法,结合实例形式分析了Android开发中关于缓存的设置与删除技巧,需要的朋友可以参考下
 

本文实例讲述了Android开发之删除项目缓存的方法。分享给大家供大家参考,具体如下:

如何删除项目的缓存:

getCacheDir()能够得到当前项目的缓存地址

在项目中经常会使用到WebView 控件,当加载html 页面时,会在/data/data/应用package 目录下生成database与cache 两个文件夹。请求的url 记录是保存在WebViewCache.db,而url 的内容是保存在WebViewCache 文件夹下

打开关闭使用缓存,一共有五个种类

//优先使用缓存:WebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//不使用缓存:WebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

在退出应用的时候加上如下代码

File file = CacheManager.getCacheFileBaseDir();if (file != null && file.exists() && file.isDirectory()) {    for (File item : file.listFiles()) {        item.delete(); }    file.delete(); }context.deleteDatabase("WebView.db");context.deleteDatabase("WebViewCache.db");
 


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表