I am getting window leak error at runtime because of using an AlertDialog.
I have pointed out the error line in the code below:
Stacktrace:<
You must need to dismiss/cancel your dialog once activity is finishing. It occurs usually if dialogs are not dismissed before Activity is ended.
I don't know does this help but at me problem's were causing multidex. At build.gradle
multiDexEnabled false
You can also get a WindowLeaked exception if you're not in the UI thread when attempting to show the dialog. Easy fix:
this.runOnUiThread(new Runnable() {
@Override
public void run() {
// show dialog here
}
});
You get error because ProgressDialog
is running while your Activity
is destroyed. You should dismiss dialog before starting new Activity
.
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
}
});
I hope it helps!
Dismiss the alertDialog in onPause() method. i.e. call alertDialog.dismiss()
Note : WindowLeaked exceptions are occured usually if dialogs are not dismissed before Activity is ended.
Check in your manifest if you have setted internet permissions:
<uses-permission android:name="android.permission.INTERNET" />