欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)之刪除項目緩存的方法

 更新時間:2016年02月05日 11:57:41   作者:lee0oo0  
這篇文章主要介紹了Android開發(fā)之刪除項目緩存的方法,結(jié)合實例形式分析了Android開發(fā)中關(guān)于緩存的設(shè)置與刪除技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之刪除項目緩存的方法。分享給大家供大家參考,具體如下:

如何刪除項目的緩存:

getCacheDir()能夠得到當前項目的緩存地址

在項目中經(jīng)常會使用到WebView 控件,當加載html 頁面時,會在/data/data/應(yīng)用package 目錄下生成database與cache 兩個文件夾。請求的url 記錄是保存在WebViewCache.db,而url 的內(nèi)容是保存在WebViewCache 文件夾下

打開關(guān)閉使用緩存,一共有五個種類

//優(yōu)先使用緩存:
WebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//不使用緩存:
WebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

在退出應(yīng)用的時候加上如下代碼

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");

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論