How can I change webview timeout? Now I'm using dirty code like this, but I think that it's not a good solution. Somewhere must be a proper mechanism of setting page loading timeout.
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);
}
}
UPDATE I wanna have something like this:
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;
}
}
}