android - showDialog(); error
<p>I trying to write if else condition for wifi connection but it throwing error.</p>

<p>Logcat</p>

<pre><code>05-04 13:32:51.227: E/WindowManager(4355): Activity com.smartmenu.SplashActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41813bd0 that was originally added here
05-04 13:32:51.227: E/WindowManager(4355): android.view.WindowLeaked: Activity com.smartmenu.SplashActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41813bd0 that was originally added here
05-04 13:32:51.227: E/WindowManager(4355):  at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:343)
05-04 13:32:51.227: E/WindowManager(4355):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:245)
05-04 13:32:51.227: E/WindowManager(4355):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
05-04 13:32:51.227: E/WindowManager(4355):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
05-04 13:32:51.227: E/WindowManager(4355):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.Dialog.show(Dialog.java:274)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
05-04 13:32:51.227: E/WindowManager(4355):  at com.smartmenu.SplashActivity.showDialog(SplashActivity.java:205)
05-04 13:32:51.227: E/WindowManager(4355):  at com.smartmenu.SplashActivity.onCreate(SplashActivity.java:93)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.Activity.performCreate(Activity.java:4465)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-04 13:32:51.227: E/WindowManager(4355):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 13:32:51.227: E/WindowManager(4355):  at android.os.Looper.loop(Looper.java:137)
05-04 13:32:51.227: E/WindowManager(4355):  at android.app.ActivityThread.main(ActivityThread.java:4340)
05-04 13:32:51.227: E/WindowManager(4355):  at java.lang.reflect.Method.invokeNative(Native Method)
05-04 13:32:51.227: E/WindowManager(4355):  at java.lang.reflect.Method.invoke(Method.java:511)
05-04 13:32:51.227: E/WindowManager(4355):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-04 13:32:51.227: E/WindowManager(4355):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-04 13:32:51.227: E/WindowManager(4355):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Code</p>

<pre><code>  if(str.equals(""))
        {                          
           ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);    
        if (mWifi.isConnected()) {
           new Handler().postDelayed(new Runnable(){
                @Override
                public void run() {
                /* Create an Intent that will start the Menu-Activity.*/ 
                Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
                SplashActivity.this.startActivity(mainIntent);
                SplashActivity.this.finish();
                }
            }, SPLASH_DISPLAY_LENGHT);
        }
        else
        {                   
            showDialog();
        }
        }
        else
        {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
            NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);    
            if (mWifi.isConnected()) {                  
                  new Handler().postDelayed(new Runnable(){
                        @Override
                        public void run() {
                        /* Create an Intent that will start the Menu-Activity.*/ 
                        Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
                        SplashActivity.this.startActivity(mainIntent);
                        SplashActivity.this.finish();
                        }
                    }, SPLASH_DISPLAY_LENGHT);
                new DownloadFilesTask().execute();
            }
            else
            {                   
                showDialog();
            }
</code></pre>

<p>showDialog();</p>

<pre><code>  private void showDialog()
    {
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("Attention");
        dialog.setMessage("No Internet Connection. Please enable the wifi. ");
        dialog.setPositiveButton("OK", new 
                DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, 
                int whichButton) 
                {
                    new Handler().postDelayed(new Runnable(){
                        @Override
                        public void run() {
                        /* Create an Intent that will start the Menu-Activity.*/ 
                        Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
                        SplashActivity.this.startActivity(mainIntent);
                        SplashActivity.this.finish();
                        }
                    }, SPLASH_DISPLAY_LENGHT);
                }
            });

        dialog.show();
    }
</code></pre>
