I have a base Activity that extends FragmentActivity
. In this activity I have a dialog with an OK button. The dialog says there's no internet connection. After a user clicks on the button the activity finishes.
I'm aware that before exiting an activity I must call dismiss
on an AlertDialog
object. I tried to do that with two ways: in the onClick
method of the DialogInterface.OnClickListener
object
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
BaseActivity.this.finish();
}
});
After I realized the previous code didn't work I tried to make a member variable in my BaseActivity class and calling the dismiss
method onDestroy
:
@Override
protected void onDestroy() {
super.onDestroy();
if (alertDialog != null) {
alertDialog.dismiss();
alertDialog = null;
}
}
It didn't work either. I still get this in my debugger:
01-07 01:43:10.815 3055-3055/com.example.app E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.app.ArticlesActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1a183701 V.E..... R....... 0,0-1026,640} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:298)
at com.example.app.BaseActivity.showErrorDialog(BaseActivity.java:145)
at com.example.app.BaseActivity.onCreate(BaseActivity.java:57)
at com.example.app.ArticlesActivity.onCreate(ArticlesActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Thank you in advance for your help.