Java disposeWhenFinished()导致API 21崩溃
以下onDestroy方法使我的应用程序在API 21上运行时崩溃(例如,当我旋转屏幕时): 该方法来自谷歌在其应用内计费教程中提供的IabHelper类Java disposeWhenFinished()导致API 21崩溃,java,android,in-app-purchase,Java,Android,In App Purchase,以下onDestroy方法使我的应用程序在API 21上运行时崩溃(例如,当我旋转屏幕时): 该方法来自谷歌在其应用内计费教程中提供的IabHelper类 /** * Disposes of object, releasing resources. If there is an in-progress async operation, this * method will queue the dispose to occur after the operation has finished.
/**
* Disposes of object, releasing resources. If there is an in-progress async operation, this
* method will queue the dispose to occur after the operation has finished.
*/
public void disposeWhenFinished() {
synchronized (mAsyncInProgressLock) {
if (mAsyncInProgress) {
logDebug("Will dispose after async operation finishes.");
mDisposeAfterAsync = true;
} else {
try {
dispose();
} catch (IabAsyncInProgressException e) {
// Should never be thrown, because we call dispose() only after checking that
// there's not already an async operation in progress.
}
}
}
}
这是错误消息:
java.lang.RuntimeException: Unable to destroy activity {package name}: java.lang.IllegalArgumentException: Service not registered: packagename.util.IabHelper$1@3bf48617
我找不到解决方案,这让我很惊讶,因为这种方法是应用内计费所必需的。您需要在
onDestroy()
super调用之前或在onPause()
中的某个地方释放IABHeloper,以确保您的活动将使用isFinishing()
方法完成,因为不能保证执行ondestory()
super调用之后的代码
应在活动上下文与播放计费服务解除绑定之前完成处置。您收到该消息是因为当您的应用程序已释放与该服务的连接时,您可能遇到了这种情况。您需要在
onDestroy()
超级调用之前或在onPause()
中的某些位置释放您的IbaHelper,以确保您的活动将使用isFinishing()
方法完成,因为不能保证执行ondestory()
super调用之后的代码
应在活动上下文与播放计费服务解除绑定之前完成处置。您收到该消息是因为当您的应用程序释放与服务的连接时,您可能遇到了问题。您是否尝试过android:configChanges=“keyboardHidden | orientation”您是否尝试过android:configChanges=“keyboardHidden | orientation”谢谢您的回答。这不起作用,但我发现原因是谷歌提供的IabHelper方法中有一个bug。此行:if(mContext!=null)mContext.unbindService(mServiceConn);必须更改为:if(mContext!=null&&mService!=null)mContext.unbindService(mServiceConn);谢谢你的回答。这不起作用,但我发现原因是谷歌提供的IabHelper方法中有一个bug。此行:if(mContext!=null)mContext.unbindService(mServiceConn);必须更改为:if(mContext!=null&&mService!=null)mContext.unbindService(mServiceConn);
java.lang.RuntimeException: Unable to destroy activity {package name}: java.lang.IllegalArgumentException: Service not registered: packagename.util.IabHelper$1@3bf48617