What is this error, and why does it happen?
05-17 18:24:57.069: ERROR/WindowManager(18850): Activity com.mypkg.myP has leaked window com.android.internal.pol
You can get this exception by just a simple/dumb mistake, by (for example) accidentally calling finish()
after having displayed an AlertDialog
, if you miss a break call statement in a switch statement...
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.new_button:
openMyAlertDialog();
break; <-- If you forget this the finish() method below
will be called while the dialog is showing!
case R.id.exit_button:
finish();
break;
}
}
The finish()
method will close the Activity
, but the AlertDialog
is still displaying!
So when you're staring intently at the code, looking for bad threading issues or complex coding and such, don't lose sight of the forest for the trees. Sometimes it can be just something as simple and dumb as a missing break statement. :)