What is overridding URL loading in WebView client?

The doc says-

    /**
     * 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.
     * This method is not called for requests using the POST "method".
     *
     * @param view The WebView that is initiating the callback.
     * @param url The url to be loaded.
     * @return True if the host application wants to leave the current WebView
     *         and handle the url itself, otherwise return false.
     */
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }

What exactly is the difference b/w the host application handling the url opposite to when WebView handles the url?

Upvotes: 0

Views: 41

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

The "host application" is what you are writing. Hence, "the host application handling the url" is when you, as the developer, decide what to do with the URL.

The implementation of WebView was written by other developers. Hence, "the WebView handles the url" is when those developers decide what to do with the URL.

Classically, WebView would handle the URL by calling startActivity() on an ACTION_VIEW Intent wrapping the URL, to launch that URL in a standalone Web browser. An app developer might use shouldOverrideUrlLoading() to call loadUrl() on the WebView itself, to keep the URL within the WebView (and, hence, within the app).

Upvotes: 1

Related Questions