Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please, don't call <code>progressDialog.dismiss();</code> from <code>doInBackground()</code>, use <code>onPostExecute()</code> instead. <code>doInBackground()</code> is not an UI thread, so trying to manipulate UI elements might give you wild consequences.</p> <p>Here's why you don't get your page loaded on the first try:</p> <pre><code> public boolean shouldOverrideUrlLoading(WebView view, String url) { new checkConnection().execute(); &lt;- (1) if (mConnection == true){ &lt;- (2) view.loadUrl(url); } return true; </code></pre> <p>(1) starts asynchronous task, which is going to be finished some time in the future (2) tries to check the results of (1) <strong>immediately</strong>, so there are no results yet.</p> <hr> <p>here's modified version of your <code>AsyncTask</code>, which accepts url as a parameter:</p> <pre><code>public class checkConnection extends AsyncTask&lt;String, Void, String&gt;{ &lt;------ change this int mStatusCode = 0; Exception mConnectionException; @Override protected void onPreExecute(){ super.onPreExecute(); progressDialog = ProgressDialog.show(WebviewActivity.this, "", "Loading...", true); progressDialog.show(); } @Override protected Void doInBackground(String... params) { &lt;------ change this try { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo().isConnectedOrConnecting()) { URL url = new URL(webLink); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setConnectTimeout(1000 * 5); // mTimeout is in seconds urlc.connect(); mStatusCode = urlc.getResponseCode(); if (mStatusCode == 200){ //Nothing to do. } } } catch (IOException e) { e.printStackTrace(); mConnectionException = e; } return params[0]; &lt;------ change this } @Override protected void onPostExecute(String param){ &lt;------ change this progressDialog.dismiss(); if (mStatusCode == 200){ myWebView.loadUrl(param); &lt;------ change this } else if (mStatusCode == 404){ myWebView.loadUrl("file:///android_asset/errorpage404.html"); } else { myWebView.loadUrl("file:///android_asset/errorpage.html"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload