Issue
I have this code:
private final class MyWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
url = "localhost:999";
mIsLoaded = false;
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
mIsLoaded = true;
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
mIsLoaded = false;
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
What is the relation and order of the overridden events
in case of success?
in case of failure?
MyWebClient should set a dialog content
but i want it to hide the dialog if my error code is not 0.
Should I do a "return" in onReceivedError
only or onPageFinished
is called anyway?
Solution
onPageFinished
tells you that the WebView has stopped loading. onReceivedError
tells you there was an error. They're not "success" and "failure" callbacks which is why you'll get both in case of an error.
Also, the callback implementations in WebViewClient usually don't do anything useful, so it makes no difference wither you're calling super.onReceivedError
or not. There is no way to "do a return" in onReceivedError
. If you want to display something else in case of an error then call view.loadUrl(...)
from onReceivedError
.
Answered By - marcin.kosiba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.