【问题标题】:Webview doesn't clear history, cache etcWebview 不会清除历史记录、缓存等
【发布时间】:2019-12-23 11:29:16
【问题描述】:

我有一个具有原生框架的 android 应用程序,内容本身以 web 格式和 webview 呈现。该应用程序的含义是允许用户使用预定义的设备 可能需要身份验证的服务。

当我在用户完成他/她的任务后尝试清理 webview 缓存时,webview 会记住所有内容,例如登录凭据已到位,历史记录仍然存在等。

我已尝试以下方法进行清理但没有成功,我在这方面缺少什么?

(如果 webview 所在的覆盖片段是每个服务正在使用的覆盖片段,则 wvfo)

wvfo.getWebView().clearCache(true);
wvfo.getWebView().clearFormData();
wvfo.getWebView().clearHistory();
wvfo.getWebView().clearMatches();
// wvfo.getWebView().setWebViewClient(new WebViewClient());
// wvfo.loadUrl("javascript:document.open();document.close();");
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();  
wvfo.destroyWebview();

任何想法这有什么问题以及为什么历史没有被清除?

提前致谢

【问题讨论】:

  • 什么时候在片段中调用这段代码?

标签: android caching webview


【解决方案1】:

是的,您还必须删除 webview 默认数据库。检查下面的代码。

static void clearWebViewAllCache(Context context, WebView webView) {
try {
AgentWebConfig.removeAllCookies(null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
context.deleteDatabase("webviewCache.db");
context.deleteDatabase("webview.db");
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);
} catch (Exception ignore) {
//ignore.printStackTrace();
if (AgentWebConfig.DEBUG) {
  ignore.printStackTrace();
}
}
}

希望对你有所帮助。

编码愉快...

【讨论】:

  • 谢谢,这是缺少的和平
  • 再次嗨,实际上这仍然没有解决所有问题。这个解决方案仍然会在内存中留下 ww-page search-field 单词,我怎样才能删除这些呢?这些在哪里以及如何删除它们?
  • 试试这个:stackoverflow.com/questions/2465432/… 可能会奏效
  • 嗨,这也不起作用。我不确定这是否与旧版本的android有关。问题出现在 android 7 平台,如果我使用三星 8.0 或更高版本的 android 平板电脑,这工作正常。
猜你喜欢
  • 2014-05-27
  • 2012-11-10
  • 1970-01-01
  • 1970-01-01
  • 2012-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
相关资源
最近更新 更多