Tuesday, 9 May 2023

WebViewClient.shouldOverrideUrlLoading() documentation clarification

Referring to the API level 24+ only version of shouldOverrideUrlLoading, the documentation clearly states:

Note: Do not call WebView#loadUrl(String) with the request's URL and then return true. This unnecessarily cancels the current load and starts a new load with the same URL. The correct way to continue loading a given URL is to simply return false, without calling WebView#loadUrl(String).

However, in my app I have to perform some extra activities before loading the URL that could only be done in MyWebView#loadUrl(String) and so I do call MyWebView#loadUrl from within MyWebViewClient#shouldOverrideUrlLoading then return true;.

This seems to work fine but I now have some doubts:

Does this warning about "the correct way to continue loading a given URL" mean that if I am not following it, this code could break

  • in the future (as in "using undocumented internal API")
  • or break now with some "unusual website"?

In what scenarios (e.g. frames, iframes, 301/302 redirects) this return true; scheme could break proper URL loading?



from WebViewClient.shouldOverrideUrlLoading() documentation clarification

No comments:

Post a Comment