title: load file_a.html with internet, load file_b.html if there is no Internet
body: <p>I am making an App in Android Studio. I am using webview. When someone opens the app, I want</p>
  <p>load <strong>file_a.html</strong> with internet from assets folder</p>
  <p>load <strong>file_b.html</strong> if there is no Internet from assets folder</p>
  <p>How to do this? I have written this code in MainActivity.java</p>
  <p>Where is the mistake? Even Back button is not functioning peoperly.</p>
  <pre><code>import androidx.appcompat.app.AppCompatActivity;
  
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.os.Bundle;
  import android.view.View;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class MainActivity extends AppCompatActivity {
  
      private boolean isNetworkAvailable () {
          ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
          NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
          return activeNetworkInfo != null &amp;&amp; activeNetworkInfo.isConnected();
      }
  
      private WebView webView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          webView = findViewById(R.id.webview);
          webView.getSettings().setJavaScriptEnabled(true);
  
          if (!isNetworkAvailable()) {
              webView.loadUrl(&quot;file:///android_asset/file_a.html&quot;);
          } else {
              webView.loadUrl(&quot;file:///android_asset/file_b.html&quot;);
  
          }
  
          @Override
          public void onBackPressed ()
          {
              if (webView.canGoBack()) {
                  webView.goBack();
              } else {
                  super.onBackPressed();
              }
          }
          
      }
  }
  </code></pre>