LicenseChecker的checkAccess泄漏ServiceConnection [英] LicenseChecker checkAccess leaks ServiceConnection
问题描述
我在LogCat中我每次preSS在我的应用程序的返回
按钮时,接收到这个异常
活动已泄漏ServiceConnection com.android.vending.licensing.LicenseChecker@471cc039这是 原来这里的约束
在code负责该泄漏的onCreate()
是:
mLicenseCheckerCallback =新MyLicenseCheckerCallback();
mChecker.checkAccess(mLicenseCheckerCallback);
我如何摆脱这种泄漏?
我试过分配MyLicenseCheckerCallback一个成员,或许思维活动时进入的onPause()
引用回调负责泄漏:
mChecker.checkAccess(新MyLicenseCheckerCallback());
但是,这并不能摆脱泄漏。
更新:感谢@ zapl的下面的评论,我看着谷歌的 LicenseChecker.java
:
/ **取消绑定服务,并在必要时删除引用。 * /
私人无效cleanupService(){
如果(MSERVICE!= NULL){
尝试 {
mContext.unbindService(本);
}赶上(抛出:IllegalArgumentException E){
//不知怎的,我们已经取消绑定。这是一个非致命错误。
Log.e(TAG,无法从许可服务(已绑定)解除绑定);
}
MSERVICE = NULL;
}
}
起初,我以为我可以忽略称呼它,但我双重检查我的(上午)的调用 mChecker.onDestroy();
在我活动的的onDestroy()
。
我还检查的onDestroy()
在 LicenseChecker.java
和它的是的呼唤 unbindService
:
/ **
*告知的上下文即将被破坏,从而使该库
*所有打开的连接,可以清理。
*所述p为H.;
*如果不调用此方法可能会导致在某些崩溃
*的情况下,如屏幕旋转,如果一个活动的请求时
*许可证检查或当用户退出应用程序。
* /
市民同步无效的onDestroy(){
cleanupService();
mHandler.getLooper()退出()。
}
那么,什么是怎么回事?
这是在拉特一个错误?
我刚刚得到了同样的问题,并与您的更新和zapl的评论我想通了,这个问题是您正在使用的仿真器。
该仿真器不具备的谷歌播放API和LVL无法绑定到该服务,留下连接打开,到了最后LVL不能用的onDestroy调用关闭它。
只需创建一个新的AVD采用Android XX的谷歌的API,而不是和试试你的code那里,如果你鸵鸟政策创建新的AVD的Android SDK管理器下载时,发现谷歌的API在目标下拉。
I am receiving this exception in LogCat every time I press the Back
button in my app:
Activity has leaked ServiceConnection com.android.vending.licensing.LicenseChecker@471cc039 that was originally bound here
The code responsible for this leak in onCreate()
is:
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
mChecker.checkAccess(mLicenseCheckerCallback);
How do I get rid of this leak?
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());
But that didn't get rid of the leak.
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;
}
}
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()
.
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?
Is this a bug in LVL?
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.
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.
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屋!