Android Webview shouldOverrideUrlLoading method

感情迁移 提交于 2020-02-14 02:41:52

问题


When is shouldOverrideUrlLoading method called?

webView.setWebViewClient(new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {


    }
});
  1. Is it called during initial loading of url? e.g. webView.loadUrl( "file:///android_asset/html/index.html");
  2. Is it called everytime URL of webview changes?

Any reference? I didn't find one. Thanks


回答1:


  1. It does however, get called when the WebView to load a different URL from the one the user had requested.

  2. Calling loadUrl() will also trigger the shouldOverrideUrlLoading() method. (Only when a new url is about to be loaded.)

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

Ref : public boolean shouldOverrideUrlLoading (WebView view, String url)




回答2:


Below is the answer for your both the questions:

As per the document, it will manage every time new URL is about to load in current WebView.



来源:https://stackoverflow.com/questions/16669046/android-webview-shouldoverrideurlloading-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!