简体   繁体   English

无论如何,`onReceivedError`之后调用`onPageFinished`?

[英]is `onPageFinished` is called after `onReceivedError` in anyway?

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 MyWebClient应设置对话框内容

but i want it to hide the dialog if my error code is not 0. 但如果我的错误代码不是0,我希望它隐藏对话框。

Should I do a "return" in onReceivedError only or onPageFinished is called anyway? 我应该仅在onReceivedError执行“返回”,还是onPageFinished

onPageFinished tells you that the WebView has stopped loading. onPageFinished告诉您WebView已停止加载。 onReceivedError tells you there was an error. onReceivedError告诉你有错误。 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. 此外, WebViewClient中回调实现通常不会执行任何有用的操作,因此无论是否调用super.onReceivedError都没有任何区别。 There is no way to "do a return" in onReceivedError . onReceivedError无法“返回”。 If you want to display something else in case of an error then call view.loadUrl(...) from onReceivedError . 如果要在出现错误时显示其他内容,请从onReceivedError调用view.loadUrl(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM