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");
    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    AtCoDeer and Election Report
    乒乓球
    dp(装箱)
    《非你莫属》面试者现场跟面试官用英文对话,一口流利的英语口语厉害了
    冬天喝酸奶,可以加热吗?冬天喝酸奶,这4个方面要注意
    滑县两个富豪打赌,一人吃了一泡狗屎
    为什么外国富豪都喜欢捐光所有财产
    发的微博有敏感词
    社交网络
    怎么把word中的文字拉细变瘦长
  • 原文地址:https://www.cnblogs.com/hudabing/p/3186004.html
Copyright © 2011-2022 走看看