LicenseChecker checkAccess泄漏ServiceConnection [英] LicenseChecker checkAccess leaks ServiceConnection

查看:15
本文介绍了LicenseChecker checkAccess泄漏ServiceConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次在我的应用中按下 Back 按钮时,我都会在 LogCat 中收到此异常:

I am receiving this exception in LogCat every time I press the Back button in my app:

Activity 泄露了 ServiceConnectioncom.android.vending.licensing.LicenseChecker@471cc039 那是原定于此

Activity has leaked ServiceConnection com.android.vending.licensing.LicenseChecker@471cc039 that was originally bound here

onCreate() 中导致此泄漏的代码是:

The code responsible for this leak in onCreate() is:

mLicenseCheckerCallback = new MyLicenseCheckerCallback();
mChecker.checkAccess(mLicenseCheckerCallback);

如何消除这种泄漏?

我尝试不将 MyLicenseCheckerCallback 分配给成员,认为当活动进行时 onPause() 对回调的引用是造成泄漏的原因:

I tried not assigning MyLicenseCheckerCallback to a member, thinking perhaps when the activity goes onPause() the reference to the callback is responsible for the leak:

mChecker.checkAccess(new MyLicenseCheckerCallback());

但这并没有消除泄漏.

更新:感谢@zapl 在下方的评论,我查看了 Google 的 LicenseChecker.java:

Update: Thanks to @zapl's comment below, I looked at Google's LicenseChecker.java:

/** 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;
    }
}

起初我以为我可能忽略了调用它,但我仔细检查了一下,我 am 在我的活动的 中调用 mChecker.onDestroy();>onDestroy().

At first I thought that I may be neglecting to call it, but I double-checked and I am calling mChecker.onDestroy(); in my activity's onDestroy().

我还在 LicenseChecker.java 中检查了 onDestroy(),它 正在 调用 unbindService:

I also checked onDestroy() in LicenseChecker.java and it is calling unbindService:

/**
 * Inform the library that the context is about to be destroyed, so that
 * any open connections can be cleaned up.
 * <p>
 * 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();
}

那么,到底发生了什么?

So, what is really going on?

这是 LVL 中的错误吗?

Is this a bug in LVL?

推荐答案

我刚遇到同样的问题,根据您的更新和 zapl 的评论,我发现问题出在您使用的模拟器上.

I just got the same problem, and with your update and zapl's comment I figured up that the problem is the emulator you are using.

此模拟器没有 Google Play API,LVL 无法绑定到服务,使连接保持打开状态,最后 LVL 无法通过 onDestroy 调用关闭它.

This Emulators don't have the Google Play APIs, and the LVL can't bind to the service, leaving a connection open, at the end LVL can't close it with the onDestroy call.

只需使用 Google API 而不是 Android xx 创建一个新的 AVD 并在那里尝试您的代码,如果您在创建新的 AVD 时在目标下拉列表中没有找到 Google API,请使用 Android SDK 管理器下载它.

Just create a new AVD using Google APIs instead of Android x.x and try your code there, if you don´t find the Google APIs in the Target pulldown when creating the new AVD download it with the Android SDK Manager.

这篇关于LicenseChecker checkAccess泄漏ServiceConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆