title: How to close an android app if webview is not able to load a webpage
body: <p>Basically my android app loads a link on a webview which i do not want to be displayed if there is no internet connection, so i want to either force close the app or hide the link from the user. Below  is my code</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class AndroidMobileAppSampleActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
  
      WebSettings webSettings = mainWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
  
      mainWebView.setWebViewClient(new MyCustomWebViewClient());
      mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  
      mainWebView.loadUrl("my link which should not be displayed to user");
  }
  
  private class MyCustomWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
          return true;
      }
  }
  }`enter code here`
  </code></pre>
  
  <p>i have tried connection manager, finish(),System.out.exit(0) and other functions, but it does not kill the app. So any help would be great.</p>