的WebView使用loadURL仅一次WebView、loadURL

2023-09-05 08:38:37 作者:没心没肺总好过撕心裂肺

编辑:我多年前曾在这个项目上,不幸的是我无法验证,如果任何的答案是工作在给定的情景

我有很难有一个的WebView应表现出我们的博客。当initilized,它工作得很好。用户可以浏览到的WebView中的不同环节。要返回到博客上,有哪些应该重新加载主博客网站的web视图外的按钮。

的问题是,没有东西来使用loadURL第二呼叫之后加载。这是我的code:

 私人的WebView WV;

        @覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

            this.setContentView(R.layout.blog);

    WV =(web视图)findViewById(R.id.blog_webview);
    wv.getSettings()setJavaScriptEnabled(真)。
    wv.setWebViewClient(新WebViewClient(){

        @覆盖
        公共无效onPageStarted(web视图查看,字符串URL,位图图标{
            MyLog.logDump(onPageStarted:+网址);
        }

        @覆盖
        公共无效onPageFinished(web视图查看,字符串URL){
                            MyLog.logDump(onPageFinished:+网址);
        }
    });

    wv.loadUrl(Constants.BLOG_URL);
}
 

称为我OnClickListener的功能如下:

 公共无效reLoadUrl(){
        wv.loadUrl(Constants.BLOG_URL);

}
 

但是,尽管在onPageFinished和​​onPageStarted日志显示该我wv.loadUrl被调用,并且它的加载正确的URL,在web视图内容本身不会改变。我已经试过清除缓存,历史,视图,尝试了不同的WebSettings,试图用webView.goBack() - 没有结果。还有那些思想不工作:

有时候,reLoadUrl示出所期望的结果 - 但一旦它失败它不再可重新工作。任何想法可能是这样吗?我曾尝试阅读的WebView code,但我无法找到任何东西,可以帮助我。

webview如何返回上一页

这是我可以添加的唯一的事情是,我们正在使用一些广告网络这是严重依赖于webViews - 我试图把这些下来,但我并没有删除库,所以我不知道他们是不是罪魁祸首。

任何想法??

解决方案

我已经花了一天左右的工作是利用一个web视图的应用程序。我也有一些问题,将数据加载到web视图。

我不能完全肯定这会工作,但也许这种替换code:

 公共无效reLoadUrl(){
    wv.loadUrl(Constants.BLOG_URL);
 

}

本code:

公共无效reLoadUrl(){

  wv.clearView();
    wv.loadUrl(Constants.BLOG_URL);
 

}

也许当你明确的WebView它会解决这个问题。

EDIT: I worked on this project years ago and unfortunately I cannot verify if any of the answers is working in the given scenario.

I am having hard time with one WebView which should show our blog. When initilized, it works just fine. The user can navigate to different links within the WebView. To get back to the blog, there is a button outside the WebView which should load the main blog site again.

The problem is, that nothing is loaded after the second call to loadUrl. Here is my code:

private WebView wv;

        @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

            this.setContentView(R.layout.blog);

    wv = (WebView) findViewById(R.id.blog_webview);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon {
            MyLog.logDump("onPageStarted: " + url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
                            MyLog.logDump("onPageFinished: " + url);
        }
    });

    wv.loadUrl(Constants.BLOG_URL);
}

The function called by my OnClickListener is the following:

    public void reLoadUrl() {
        wv.loadUrl(Constants.BLOG_URL);

}

But despite that the logs in onPageFinished and onPageStarted show that my wv.loadUrl is being invoked and that it's loading the correct url, the content in the webview itself doesn't change. I've tried clearing the cache, the history, the view, tried different WebSettings, tried to use webView.goBack() - not result. Also those ideas don't work: Strange webview goBack issue in android

Sometimes, the reLoadUrl shows the desired result - but once it fails it no longer can be made to work again. Any ideas what could be happening? I did try to read the WebView code but I couldn't find anything that could help me.

The only thing that I can add, is that we are using some ad networks which are heavily dependent on webViews - I tried to turn those down, but I didn't remove the libraries so I am not sure that they are not the culprit.

Any ideas??

解决方案

I have spent the last day or so working on an application that utilised a WebView. I did have a few issues with loading data into the WebView.

I am not entirely sure this would work but perhaps replace this code:

public void reLoadUrl() {
    wv.loadUrl(Constants.BLOG_URL);

}

with this code:

public void reLoadUrl() {

    wv.clearView();
    wv.loadUrl(Constants.BLOG_URL);

}

maybe when you clear the WebView it will solve the issue