title: Error : Launcher dialog dismiss failed : java.lang.IllegalArgumentException
body: <p>I have asked this question earlier <a href="https://stackoverflow.com/questions/47369115/android-error-launcher-dialog-dismiss-failed">here</a> but no one was able to answer that one as well. The problem is that in my activity oncreate i am creating a alert dialog and this method runs perfectly on android 5.0 but in android API less than 5 I get an error:</p>
  
  <p>Logcat:</p>
  
  <pre><code>E/HwLauncher: Launcher dialog dismiss failed : java.lang.IllegalArgumentException: no dialog with id 1 was ever shown via Activity#showDialog
  </code></pre>
  
  <p>below is my code for activity</p>
  
  <pre><code>  private static int SPLASH_TIME_OUT = 3000;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_splash);
  
          // Alert Box
  
          final AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Internet  not connected");
          builder.setMessage("You need to connect WiFi/Mobile-Data run this app.");
          builder.setCancelable(false);
  
          builder.setPositiveButton(
                  "Go to Settings",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
  
                          startActivity(new Intent(Settings.ACTION_SETTINGS));
                          finish();
                      }
                  });
  
          builder.setNegativeButton(
                  "Cancel",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          finish();
                      }
                  });
          final AlertDialog alert = builder.create();
          alert.show();
  
          ConnectivityManager cm = (ConnectivityManager)
                  getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  
          if (networkInfo != null){
  
              alert.dismiss();
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      // This method will be executed once the timer is over
                      // Start your app main activity
                      Intent i = new Intent(splash.this, LoginActivity.class);
                      startActivity(i);
                      // close this activity
                      finish();
                  }
              }, SPLASH_TIME_OUT);
  
          }
      }
  </code></pre>
  
  <p>I have tried other answers from stackoverflow <a href="https://stackoverflow.com/questions/10225043/alert-dialog-dismiss-not-happing">like this one</a> but none of these answers helped me</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have commented out the AlertDialog part of the code but the error still persists. Below is the code I am using now without alertdialog</p>
  
  <pre><code>public class splash extends AppCompatActivity {
  
      private static int SPLASH_TIME_OUT = 3000;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_splash);
  
  
          new Handler().postDelayed(new Runnable() {
              @Override
              public void run() {
                  // This method will be executed once the timer is over
                  // Start your app main activity
                  Intent i = new Intent(splash.this, LoginActivity.class);
                  startActivity(i);
                  // close this activity
                  finish();
              }
          }, SPLASH_TIME_OUT);
          // Alert Box
  
          /*
          final AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Internet  not connected");
          builder.setMessage("You need to connect WiFi/Mobile-Data run this app.");
          builder.setCancelable(false);
  
          builder.setPositiveButton(
                  "Go to Settings",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
  
                          startActivity(new Intent(Settings.ACTION_SETTINGS));
                          finish();
                      }
                  });
  
          builder.setNegativeButton(
                  "Cancel",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          finish();
                      }
                  });
  
          final Dialog alert = builder.create();
          alert.show();
  
          //WifiManager wifi =(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  
          ConnectivityManager cm = (ConnectivityManager)
                  getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  
  
          if (networkInfo != null){
  
              alert.dismiss();
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      // This method will be executed once the timer is over
                      // Start your app main activity
                      Intent i = new Intent(splash.this, LoginActivity.class);
                      startActivity(i);
                      // close this activity
                      finish();
                  }
              }, SPLASH_TIME_OUT);
  
          }*/
      }
  </code></pre>
  
  <p>Even with the AlertDialog commented out Logcat shows the same error:</p>
  
  <pre><code>Launcher dialog dismiss failed : java.lang.IllegalArgumentException: no dialog with id 1 was ever shown via Activity#showDialog
  </code></pre>