gpt4 book ai didi

java - disposeWhenFinished() 导致 API 21 崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 11:07:56 24 4
gpt4 key购买 nike

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

@Override
protected void onDestroy() {
super.onDestroy();
if (mHelper != null) {
mHelper.disposeWhenFinished();
mHelper = null;
}
}

该方法来自 Google 在其应用内结算教程中提供的 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.
*/
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() 中的某个位置释放 IabHelper,以确保您的 Activity 将使用 isFinishing() 方法完成,因为无法保证 onDestroy() super 调用之后的代码将被执行。

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

关于java - disposeWhenFinished() 导致 API 21 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46301626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com