title: Alert dialog builder inside the if else statement - android
body: <p>I put Alert dialog builder inside my if else statement. Now, I want to do is to automatic dismiss the dialog in "if" statement and show the dialog in "else" statement. So, here is my codes.</p>
  
  <pre><code> public void DisplayConn(){
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle("Error");
      builder.setMessage("No Network Connection").setCancelable(false);
      AlertDialog alert = builder.create();
  
      if(isNetworkStatusAvailable(getApplicationContext())){
          alert.dismiss();
      } else {
          alert.show();
      }
  }
  </code></pre>
  
  <p>I don't want to use onClick button to dismiss the dialog, I just want to automatic dismiss the dialog in "if" statement. It is possible? Thanks in advance.</p>