Note that there are some explanatory texts on larger screens.

plurals
  1. POLicenseChecker checkAccess leaks ServiceConnection
    text
    copied!<p>I am receiving this exception in LogCat every time I press the <code>Back</code> button in my app:</p> <blockquote> <p>Activity has leaked ServiceConnection com.android.vending.licensing.LicenseChecker@471cc039 that was originally bound here</p> </blockquote> <p>The code responsible for this leak in <code>onCreate()</code> is:</p> <pre><code>mLicenseCheckerCallback = new MyLicenseCheckerCallback(); mChecker.checkAccess(mLicenseCheckerCallback); </code></pre> <p>How do I get rid of this leak?</p> <p>I tried not assigning MyLicenseCheckerCallback to a member, thinking perhaps when the activity goes <code>onPause()</code> the reference to the callback is responsible for the leak:</p> <pre><code>mChecker.checkAccess(new MyLicenseCheckerCallback()); </code></pre> <p>But that didn't get rid of the leak.</p> <p><strong>Update:</strong> Thanks to @zapl's comment below, I looked at Google's <code>LicenseChecker.java</code>:</p> <pre><code>/** Unbinds service if necessary and removes reference to it. */ private void cleanupService() { if (mService != null) { try { mContext.unbindService(this); } catch (IllegalArgumentException e) { // Somehow we've already been unbound. This is a non-fatal error. Log.e(TAG, "Unable to unbind from licensing service (already unbound)"); } mService = null; } } </code></pre> <p>At first I thought that I may be neglecting to call it, but I double-checked and I <em>am</em> calling <code>mChecker.onDestroy();</code> in my activity's <code>onDestroy()</code>.</p> <p>I also checked <code>onDestroy()</code> in <code>LicenseChecker.java</code> and it <em>is</em> calling <code>unbindService</code>:</p> <pre><code>/** * Inform the library that the context is about to be destroyed, so that * any open connections can be cleaned up. * &lt;p&gt; * Failure to call this method can result in a crash under certain * circumstances, such as during screen rotation if an Activity requests * the license check or when the user exits the application. */ public synchronized void onDestroy() { cleanupService(); mHandler.getLooper().quit(); } </code></pre> <p>So, what is really going on?</p> <p>Is this a bug in LVL?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload