Android开发之删除项目缓存的方法
作者:lee0oo0 时间:2021-07-22 17:15:45
本文实例讲述了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程序设计有所帮助。
标签:Android,缓存
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c# rsa加密解密详解
2023-06-11 00:54:17
![](https://img.aspxhome.com/file/2023/4/68094_0s.png)
springboot后端配置多个数据源、Mysql数据库的便捷方法
2022-05-01 07:21:37
Java中的Static class详解及实例代码
2023-12-24 18:19:40
maven install报错中程序包xxx不存在的问题解决
2023-03-05 03:06:51
![](https://img.aspxhome.com/file/2023/9/65309_0s.jpg)
Springboot如何通过yml配置文件为静态成员变量赋值
2021-08-03 12:03:17
![](https://img.aspxhome.com/file/2023/1/78391_0s.png)
Springboot导出文件,前端下载文件方式
2023-07-21 11:27:05
![](https://img.aspxhome.com/file/2023/4/60774_0s.jpg)
springmvc 分页查询的简单实现示例代码
2022-01-09 11:08:22
深入c# Func委托的详解
2022-02-15 05:44:51
解析android中的dip,dp,px,sp和屏幕密度
2023-09-26 20:44:38
Java适配器模式_动力节点Java学院整理
2021-09-06 10:50:53
![](https://img.aspxhome.com/file/2023/6/65636_0s.jpg)
Spring Cloud 配置中心内容加密的配置方法
2023-02-11 09:05:15
分别在Groovy和Java中创建并初始化映射的不同分析
2023-11-26 08:15:42
Mybatis Lombok使用方法与复杂查询介绍
2023-03-30 00:30:13
![](https://img.aspxhome.com/file/2023/4/68764_0s.png)
JetBrains IntelliJ IDEA 配置优化技巧
2022-06-19 08:31:38
![](https://img.aspxhome.com/file/2023/7/64067_0s.png)
详解C#面相对象编程中的继承特性
2022-06-09 09:15:24
![](https://img.aspxhome.com/file/2023/6/79076_0s.png)
java中dart类详细讲解
2022-01-23 13:01:13
javaWeb项目部署到阿里云服务器步骤详解
2023-11-07 05:21:36
![](https://img.aspxhome.com/file/2023/9/58909_0s.png)
MyBatis中使用foreach循环的坑及解决
2023-11-02 12:47:51
关于Java双大括号{{}}的具体使用
2021-05-28 16:32:01
使用JSON.toJSONString格式化成json字符串时保留null属性
2023-05-10 14:56:34