title: Activity has leaked window com.android.internal.policy.PhoneWindow$DecorView{2d637e8 V.E...... R....... 0,0-768,293} that was originally added here
body: <p>I am getting window leaked error. I am trying to show a dialog with YES and NO button.If user clicks NO button then trying to close the app by calling finish() method. Problem here is that finish() method is called without showing the  dialog. I am unable to understand why dialog isn't showing.</p>
  
  <pre><code>public class LoadingActivity extends AppCompatActivity {
  
          private String TAG = LoadingActivity.class.getSimpleName();
          private Boolean isConnected;
          private Boolean retry;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_loading);
              Log.d(TAG,"onCreate()");
  
              retry = false;
              do{
                 // NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                  isConnected = MiscService.isConnectedToInternet(this);
                  if(!isConnected) {
                      Log.i(TAG,"Internet Connection: " + isConnected);
  
                      AlertDialog.Builder builder = new AlertDialog.Builder(this);
                      builder.setMessage("No Internet Connection Available. Do you want to try again?");
                      builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              retry = true;
                          }
                      });
                      builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              retry = false;
                          }
                      });
  
                      AlertDialog dialog = builder.create();
                      dialog.show();
                  }
              }while(retry);
  
              if(!isConnected ){
                  //Exit the application
                  Log.i(TAG,"Closing App...");
                  finish();
              }
  
          }
          @Override
          public void finish() {
              super.finish();
          }
      }
  </code></pre>
  
  <p>stacktrace...</p>
  
  <pre><code>06-03 09:43:35.329 21582-21582/com.example.andonsystem W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
  06-03 09:43:35.340 21582-21582/com.example.andonsystem D/LoadingActivity: onCreate()
  06-03 09:43:35.342 21582-21582/com.example.andonsystem I/LoadingActivity: Internet Connection: false
  06-03 09:43:35.402 21582-21627/com.example.andonsystem D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
  
                                                                           [ 06-03 09:43:35.411 21582:21582 D/         ]
                                                                           HostConnection::get() New Host Connection established 0xed760550, tid 21582
  06-03 09:43:35.429 21582-21582/com.example.andonsystem I/LoadingActivity: Closing App...
  
                                                                            [ 06-03 09:43:35.448  3060: 3781 D/         ]
                                                                            HostConnection::get() New Host Connection established 0xdd360300, tid 3781
  06-03 09:43:35.937 21582-21627/com.example.andonsystem D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
  06-03 09:43:35.939 21582-21627/com.example.andonsystem D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
  06-03 09:43:35.980 21582-21627/com.example.andonsystem D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
  
                                                                   [ 06-03 09:43:36.007 21582:21627 D/         ]
                                                                   HostConnection::get() New Host Connection established 0xed760f40, tid 21627
  06-03 09:43:36.053 21582-21627/com.example.andonsystem I/OpenGLRenderer: Initialized EGL, version 1.4
  06-03 09:43:36.185 21582-21627/com.example.andonsystem W/EGL_emulation: eglSurfaceAttrib not implemented
  06-03 09:43:36.185 21582-21627/com.example.andonsystem W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf04efda0, error=EGL_SUCCESS
  06-03 09:43:36.673 21582-21582/com.example.andonsystem E/WindowManager: android.view.WindowLeaked: Activity com.example.andonsystem.LoadingActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{63c85d2 V.E...... R....... 0,0-768,293} that was originally added here
                                                                              at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:368)
                                                                              at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
                                                                              at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
                                                                              at android.app.Dialog.show(Dialog.java:319)
                                                                              at com.example.andonsystem.LoadingActivity.onCreate(LoadingActivity.java:72)
                                                                              at android.app.Activity.performCreate(Activity.java:6237)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                              at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  06-03 09:43:36.708 21582-21627/com.example.andonsystem E/Surface: getSlotFromBufferLocked: unknown buffer: 0xeb1ab7a0
  </code></pre>
  
  <p>Updated Code...</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_loading);
          Log.d(TAG,"onCreate()");
  
          //retry = false;
  
  
          isConnected = MiscService.isConnectedToInternet(this);
          if(!isConnected) {
              Log.i(TAG,"Internet Connection: " + isConnected);
  
              AlertDialog.Builder builder = new AlertDialog.Builder(this);
              builder.setMessage("No Internet Connection Available. Do you want to try again?");
              builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
  
                  }
              });
              builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      Log.i(TAG,"Closing App...");
                      finish();
                  }
              });
  
              AlertDialog dialog = builder.create();
              dialog.show();
          }
  </code></pre>
  
  <p>Thanks for help in advance...</p>