From this great explanation about the differences between WebViewClient
and WebChromeClient
it seems that if you use one, you shouldn't be using the other (for the same WebView object).
Is my understanding correct?
If not, when would one use both WebViewClient
and WebChromeClient
for the same WebView
object?
Is there an example of a situation where only use both WebViewClient
and WebChromeClient
for the same WebView
object would accomplish a certain goal?
You certainly can use both, they just have different functions. Setting your own custom WebViewClient lets you handle onPageFinished, shouldOverrideUrlLoading, etc., WebChromeClient lets you handle Javascript's alert() and other functions.
Just make your own class, for example:
and / or
Just override the functions described in the documentation, then set your client in onCreate with:
You can use both clients simultaneously. It is useful as both of them provides different functionalities.
For example, if you would like to:
and
which are impossible with just one of the clients you can do the following:
As the default implementation of shouldOverrideUrlLoading(WebView, String) method can be use as-is for above mentioned case - there is no need to override it unless you would like other behavior.