• 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");
    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    hiberate关系映射大全
    SpringMVC+RestFul详细示例实战教程
    [转]为什么大型网站前端使用 PHP 后台逻辑用 Java?
    offsetWidthoffsetleft 等图文解释
    理解jquery的$.extend()、$.fn和$.fn.extend()
    使用jquery获取url及url参数的方法
    构建高并发高可用的电商平台架构实践
    jquery实现多条件筛选特效代码分享
    【转载】“活在当下”是什么含义呢?
    UL LI 布局 TAB 切换条
  • 原文地址:https://www.cnblogs.com/hudabing/p/3186004.html
Copyright © 2020-2023  润新知