如何清除的WebView历史的android [英] how to clear webview history in android

查看:2261
本文介绍了如何清除的WebView历史的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的WebView的历史是不清除...有什么不对低于code?

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...

推荐答案

您可以一边web视图是为了清除历史记录设置onPageFinished监听如下加载网页(URL)无法清除历史记录

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 insted的结算刚刚成立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

这篇关于如何清除的WebView历史的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆