1

i am getting error.

Activity com.act.hyd.app.EmtyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416e8bb8 that was originally added here

in a splash screen I will check version code of app. If it is not suitable version then show an AlertDialog. But I am getting the above error.how to solve it.

public void incorrectMessages(){


           AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

                // set title
                alertDialogBuilder.setTitle("Your Title");

                // set dialog message
                alertDialogBuilder
                    .setMessage("Click yes to exit!")
                    .setCancelable(false)
                    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                            startActivity(browserIntent);
                        }
                      })
                    .setNegativeButton("No",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.dismiss();
                        }
                    });

                    // create alert dialog
                    AlertDialog alertDialog = alertDialogBuilder.create();

                    // show it
                    alertDialog.show();




                 Toast.makeText(getApplicationContext(), "Dear ACT Customer your App looks old version .Please upgrade from Playstore ", Toast.LENGTH_LONG).show();
                 onRestart();
             }
Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
benarjee bojja
  • 348
  • 1
  • 3
  • 15
  • possible duplicate of [Activity has leaked window that was originally added](http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added) – Tim Sep 22 '15 at 11:16
  • Post the source code of the activity, I think that you could be calling the alert more than once. – Víctor Martín Sep 22 '15 at 11:24

3 Answers3

1

You need to call

alertDialogBuilder.dismiss()

before you finish the Activty.

markView
  • 333
  • 1
  • 7
0

setNegativeButton function you are have called dialog.dismiss(); but you have not dismissed your dialogbox on setPositiveButton , so you also need to dismiss your dialog box in setPositiveButton function.

OR

you can also use onDestroy(). write below function on your activity

public void onDestroy() {
super.onDestroy();

  if(dialog !=null)
  {
    dialog.dismiss();
  }
}
Abdul Aleem
  • 679
  • 8
  • 31
0

Just before you go to the new Activity, you need to close the dialog of the current activity.

.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            // --------------------------
                            // here you need to dismiss the dialog
                             dialog.dismiss();
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                            startActivity(browserIntent);

                        }
                      })

otherwise the dialog window will be leaked.

good luck

MBH
  • 16,271
  • 19
  • 99
  • 149