zoukankan      html  css  js  c++  java
  • android webview删除缓存

    [1].[代码] 删除保存于手机上的缓存. 跳至 [1] [2] [3]

    01 // clear the cache before time numDays    
    02 private int clearCacheFolder(File dir, long numDays) {         
    03     int deletedFiles = 0;        
    04     if (dir!= null && dir.isDirectory()) {            
    05         try {               
    06             for (File child:dir.listFiles()) {   
    07                 if (child.isDirectory()) {             
    08                     deletedFiles += clearCacheFolder(child, numDays);         
    09                 }   
    10                 if (child.lastModified() < numDays) {    
    11                     if (child.delete()) {                  
    12                         deletedFiles++;          
    13                     }   
    14                 }   
    15             }            
    16         catch(Exception e) {      
    17             e.printStackTrace();   
    18         }    
    19     }      
    20     return deletedFiles;    
    21 }
     

    [2].[代码] 打开关闭使用缓存 跳至 [1] [2] [3]

    1 //优先使用缓存:
    2 WebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 
    3  
    4 //不使用缓存:
    5 WebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
     

    [3].[代码] 在退出应用的时候加上如下代码 跳至 [1] [2] [3]

    01 File file = CacheManager.getCacheFileBaseDir(); 
    02    if (file != null && file.exists() && file.isDirectory()) { 
    03     for (File item : file.listFiles()) { 
    04      item.delete(); 
    05     
    06     file.delete(); 
    07    
    08    
    09   context.deleteDatabase("webview.db"); 
    10   context.deleteDatabase("webviewCache.db");
    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    PHP操作Memcache基本函数
    sublime text 设置
    获取客户端IP地址经纬度所在城市
    php 中文转拼音首字母问题
    php分类
    php +mysql 添加 删除 修改 insert into delete update
    php+mysql 内联接 和 子查询
    mysql count max min 语句用法
    mysql 查询语句
    非常不错的MySQL优化的8条经验
  • 原文地址:https://www.cnblogs.com/hudabing/p/3186004.html
Copyright © 2011-2022 走看看