-1

i'm getting above error when i use aleart dialogues in my app.even i dismiss the dialogue when i close my activity also i'm getting this error :

android.view.WindowLeaked: Activity com.Forewarn.ForewarnApp.activities.SignInActivity has leaked window DecorView@3dadc87[] that was originally added here
                                                                               at android.view.ViewRootImpl.<init>(ViewRootImpl.java:424)
                                                                               at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
                                                                               at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
                                                                               at android.app.Dialog.show(Dialog.java:316)
                                                                               at com.Forewarn.ForewarnApp.activities.SignInActivity.getFingerPrint(SignInActivity.java:707)
                                                                               at com.Forewarn.ForewarnApp.activities.SignInActivity.onCreate(SignInActivity.java:280)
                                                                               at android.app.Activity.performCreate(Activity.java:6672)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                               at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:154)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 

i tries with adding this :

 @Override
    public void onDestroy(){
        super.onDestroy();
        if (alertDialog != null && alertDialog.isShowing()){
            alertDialog.dismiss();
            SignInActivity.alertDialog.dismiss();
        }
    }

here i'm getting error in below lines :

 myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
                                myMsg.setPadding(10,50,10,0);
                                myMsg.setTextColor(getResources().getColor(R.color.colorPrimary));
                                myMsg.setTextSize(16);
                                alertDialogBuilder.setView(myMsg);
                                //alertDialogBuilder.setMessage("Please place your fingertip on the scanner to verify your identity and Login");
                                alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        //finish();
                                        Constant.isCanceled = "true";
                                        dialog.dismiss();
                                    }
                                });

                                alertDialog = alertDialogBuilder.create();
                                alertDialog.show();
Dolly
  • 11
  • 6
  • 4
    try this:-https://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added – Ravish Sharma Dec 11 '17 at 05:14
  • please guys see my question carefully, i mentioned i already tried with that code, why it is still coming idk.think about it. – Dolly Dec 11 '17 at 05:20
  • both code snippet reside in same Activity? – Omkar Dec 11 '17 at 05:33
  • yes within same activity only. – Dolly Dec 11 '17 at 05:34
  • and i use another dialogue out of activity class,which that class is called from activity thats why i created static dialogue and close that one also inside my activity. – Dolly Dec 11 '17 at 05:38
  • try to make alertDialog null in onDestroy() like below @Override public void onDestroy(){ super.onDestroy(); if (alertDialog != null && alertDialog.isShowing()){ alertDialog.dismiss(); alertDialog = null; } } – Omkar Dec 11 '17 at 05:47
  • sorry, same error still – Dolly Dec 11 '17 at 05:57

1 Answers1

0

Window leaked exceptions have this reason, showing the dialog when Activity Context doesn't exists, to solve this you should check Activity exists:

if(getActivity()!= null && !getActivity().isFinishing()){
        Dialog.show();
}
Gowtham Subramaniam
  • 3,358
  • 2
  • 19
  • 31