Saturday, July 30, 2011

Window leak problem - dismiss that dialog!

I was just testing my app and, after a while a couple of things cropped up. First, it looks like my percentage correct numbers are out of whack. I'll check that later doing some unit testing. But, more alarmingly, the android licensing again leaked a window on me, causing a crash. Here's the error message:


E/WindowManager( 7377): Activity com.jlptquiz.app.StartActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40640170 that was originally added here
E/WindowManager( 7377): android.view.WindowLeaked: Activity com.jlptquiz.app.StartActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40640170 that was originally added here
E/WindowManager( 7377): at android.view.ViewRoot.(ViewRoot.java:258)
E/WindowManager( 7377): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager( 7377): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager( 7377): at android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager( 7377): at android.app.Dialog.show(Dialog.java:241)
E/WindowManager( 7377): at android.app.ProgressDialog.show(ProgressDialog.java:107)
E/WindowManager( 7377): at android.app.ProgressDialog.show(ProgressDialog.java:90)
E/WindowManager( 7377): at com.jlptquiz.app.ValidateLicense.valdidateLicense(ValidateLicense.java:62)
E/WindowManager( 7377): at com.jlptquiz.app.StartActivity.validateLicense(StartActivity.java:307)

Actually, the one the other day was a bit different:

E/ActivityThread( 2074): Activity com.myapp.app.StartActivity has leaked ServiceConnection com.android.vending.licensing.LicenseChecker@405abfd0 that was originally bound here
E/ActivityThread( 2074): android.app.ServiceConnectionLeaked: Activity com.jlptquiz.app.StartActivity has leaked ServiceConnection com.android.vending.licensing.LicenseChecker@405abfd0 that was originally bound here

So, the new one looks like it's not canceling the progress dialog widget. Let's check the code...

Yeah, here it is, on the allow:

ValidateLicense.this.mProgressDialog
.cancel();

mChecker.onDestroy();

From some posts on StackOverflow, it looks like I may need to call dismiss. This might make the cancel redundant, but I'll add it in.

ValidateLicense.this.mProgressDialog.cancel();

ValidateLicense.this.mProgressDialog.dismiss();

Ok, I also changed the question activity to be consistent in how it was getting its application context, before I was sometimes getting it from a member, sometimes from the context. It may have solved the problem, because the next display was correct. I also haven't got the window problem - yet. I think I'll run it through another hundred questions to be sure.

That's a wrap!

No comments:

Post a Comment