1) How to set the maximum page load timeout in WebView?
2) What is the default wait?
1) How to set the maximum page load timeout in WebView?
2) What is the default wait?
You are right, this is not in the documentation. Moreover, I did not find it in the source code either. And the fact that my test program patiently waited 5 minutes for a response from my test web server suggests that there is no default timeout. It only remains to do with such crutches:
public class TimedWebViewClient extends WebViewClient { private boolean timeout; private int delay = 1000; public TimedWebViewClient() {} public TimedWebViewClient(int delay) { this.delay = delay; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { timeout = true; new Handler().postDelayed(new Runnable() { @Override public void run() { if(timeout) { view.stopLoading(); Toast.makeText(view.getContext(), "Timeout!", Toast.LENGTH_SHORT).show(); } } }, delay); } @Override public void onPageFinished(WebView view, String url) { timeout = false; } } webView.setWebViewClient(new TimedWebViewClient()); Or use a non-native WebView implementation, such as CordovaWebView.
Source: https://ru.stackoverflow.com/questions/640642/
All Articles