WebView loadUrl works only once

后端 未结 14 1731
长情又很酷
长情又很酷 2020-12-14 01:49

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 Web

相关标签:
14条回答
  • 2020-12-14 02:21

    I was facing the same issue. I was creating a new Webview everytime. Just first destroy your previous webView before creating a new one. I hope this help!! Make your webview a global variable. Like -

    Webview w;

    then before creating a new webview just destroy the previous one

                    if(null != w)
                    {
                        //destroy the previous webview, before creating the new one
                        w.destroy();
                    }
                    w= new WebView(activity);
    
    0 讨论(0)
  • 2020-12-14 02:24

    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

    0 讨论(0)
  • 2020-12-14 02:24

    I had the same issue, calling resumeTimers() solved the problem for me...

    0 讨论(0)
  • 2020-12-14 02:25

    Try to load a blank page before:

    wv.loadUrl("about:blank");
    wv.clearHistory();
    wv.clearView();
    wv.loadUrl(Constants.BLOG_URL);
    

    Edit: This is a code I used before because I had problems with this too, please try it.

    0 讨论(0)
  • 2020-12-14 02:27

    I'd suggest you try recreating the WebView every time you use it and see if that makes any difference.

    First save context, layout parms and parent.

    Context context = wb.getContext();
    ViewGroup.LayoutParams lp = wv.getLayoutParams();
    ViewGroup parent = (ViewGroup)wv.getParent();
    

    Then stop it loading and remove the view from its parent.

    wv.stopLoading();
    parent.removeView(wv);
    

    Then recreate and add it back.

    wv = new WebView(context);
    parent.addView(wv, lp);
    

    That may be other properties that you'll need to restore, but that's the general idea.

    0 讨论(0)
  • 2020-12-14 02:32

    I am facing the same issue and got it working by following steps:

    webView.clearCache(true);
    webView.loadUrl("Url");
    

    and I got the multiple url loaded successfully.

    0 讨论(0)
提交回复
热议问题