如何更改webview超时?

时间:2014-05-26 12:57:00

标签: android webview timeout

如何更改webview超时?现在我正在使用像这样的脏代码,但我认为这不是一个好的解决方案。某处必须是设置页面加载超时的正确机制。

public class HollyDollyWebViewClient extends WebViewClient {
    private static final long TIMEOUT = 30000L;

    private Handler timeoutHandler = new Handler();

    private Runnable timeoutRunnable = new Runnable() {
        @Override
        public void run() {
            //show some error message here
        }
    };

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        timeoutHandler.postDelayed(timeoutRunnable, TIMEOUT);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        timeoutHandler.removeCallbacks(timeoutRunnable);
    }
}

UPD0>我想要这样的事情:

public class HollyDollyWebViewClient extends WebViewClient {
    private static final long TIMEOUT = 30000L;

    public HollyDollyWebViewClient() {
        // set timeout value somehow
    }

    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        switch (errorCode) {
        case ERROR_TIMEOUT:
            // show error message here
            break;
        }
    }
}

0 个答案:

没有答案