如何清除网页浏览历史记录? [英] How to clear webview history?
问题描述
webview的历史没有清除...下面的代码有什么问题?
The history of webview is not clearing... What is wrong with below code?
Web 视图创建
mWebViewReport=(WebView)findViewById(R.id.report_page);
mWebViewReport.setWebViewClient(new HelloWebViewClient());
mWebViewReport.getSettings().setBuiltInZoomControls(true);
点击帮助按钮时加载帮助文件
Load help file when help button click
mWebViewReport.loadUrl("file:///android_asset/help.html");
mWebViewReport.clearHistory();
mWebViewReport.clearCache(true);
点击摘要按钮时加载摘要文件
load Summary file when summary button click
mWebViewReport.loadUrl("file:///android_asset/summary.html");
//On back button click
if (mWebViewReport.canGoBack()) {
mWebViewReport.goBack();
return ;
}
在这里我也可以看到帮助页面...
Here i can see the Help page too...
推荐答案
你不能在 webview 加载页面(url)时清除历史记录,以便清除 onPageFinished 监听器的历史设置,如下
You can't clear history while the webview is loading a page (url) in order to clear the history setup onPageFinished listener as follows
在 onCreate 之前声明一个公共变量
declare a public var before the onCreate
boolean clearHistory = false;
现在当你声明你的 mWebViewReport 时设置它
now when you declare your mWebViewReport set this up
mWebViewReport.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url)
{
if (clearHistory)
{
clearHistory = false;
mWebViewReport.clearHistory();
}
super.onPageFinished(view, url);
}
});
现在,当您调用帮助 url 以清除历史记录时,只需将 clearHistory 设置为 true
Now when you call your help url insted of clearing the history just set clearHistory to true
mWebViewReport.loadUrl("file:///android_asset/help.html");
mWebViewReport.clearHistory(); // REMOVE THIS LINE
mWebViewReport.clearCache(true); // REMOVE THIS LINE
clearHistory = true; // ADD THIS LINE
这篇关于如何清除网页浏览历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!