1) How to set the maximum page load timeout in WebView?

2) What is the default wait?

  • It is better to subload the page with subqueries, or flush. Users do not like when the page is hanging, they can request it again 10 times - and hang the server))) - nick_n_a
  • @nick_n_a, maybe better, but they are interested in the answers to these questions, I don’t notice them in the documentation, I may not look well ... - Kopkan

1 answer 1

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.

  • 1) What is the default boot timeout? 2) What will this code help me if the default time is less than I need? - Kopkan
  • Unfolded answer. - Sergey Gornostaev