disposeWhenFinished()导致API 21崩溃

时间:2017-09-19 13:21:39

标签: java android in-app-purchase

以下onDestroy方法使我的应用程序在API 21上运行时崩溃(例如,当我旋转屏幕时):

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

该方法来自Google在其应用内结算教程中提供的IabHelper类。

 java.lang.RuntimeException: Unable to destroy activity {package name}: java.lang.IllegalArgumentException: Service not registered: packagename.util.IabHelper$1@3bf48617

这是错误消息:

Writeln(result:0:2);

我无法找到解决方案,这让我感到很奇怪,因为这种方法是应用内结算所必需的。

1 个答案:

答案 0 :(得分:0)

您需要在onDestroy()超级电话之前释放您的IabHelper,或者onPause()中某些地方确保您的活动将使用isFinishing()方法完成,因为无法保证onDestroy()之后的代码{1}}超级电话将被罚款。

处理应在活动上下文与播放结算服务解除绑定之前完成。您收到该消息是因为当您的应用程序释放了该服务的连接时,您可能会遇到这种情况。