android - BillingService 泄露了 ServiceConnection

标签 android

我尝试将代码集成到 Blundell's in-app purchasing example 中进入我自己的应用程序,它几乎可以正常工作。我做了一个名为 shop.java 的 Activity ,它有一组按钮,每个按钮对应可以在我的应用程序中购买的每个可能的项目。如果我单击其中一个按钮,则会进行测试购买(“android.test.purchased”)并且似乎已成功执行。日志输出看起来令人放心:

CONFIRM_NOTIFICATIONS Sync Response code: RESULT_OK
Transaction complete
Transaction status: PURCHASED
Item purchased is: android.test.purchased
Received action: com.android.vending.billing.RESPONSE_CODE
checkResponseCode got requestId: 4731640731226687265
checkResponseCode got responseCode: RESULT_OK
Received action: com.android.vending.billing.RESPONSE_CODE
checkResponseCode got requestId: 1172244708705759861
checkResponseCode got responseCode: RESULT_OK
Received action: com.android.vending.billing.RESPONSE_CODE
checkResponseCode got requestId: 2684438012578976155
checkResponseCode got responseCode: RESULT_SERVICE_UNAVAILABLE
Key action: 4
clipservice: android.sec.clipboard.ClipboardExManager@41d443c0
Stopping Service

控制返回到 shop.java。我现在按下后退按钮返回到我的应用程序的主要 Activity 。我假设调用了 shop.java 的 onDestroy 方法,但现在我收到以下错误:

Service com.mycompany.mygame.BillingService has leaked ServiceConnection com.mycompany.mygame.BillingService@41d25498 that was originally bound here

有什么想法吗?

编辑:刚刚注意到,即使我没有尝试购买任何东西,我也会遇到完全相同的错误!

最佳答案

初始化计费服务时,尽量给它应用上下文而不是 Activity 上下文。使用:

getApplicationContext()

关于android - BillingService 泄露了 ServiceConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13125484/

相关文章:

android - 如何检索 firebase 中的数据?

android - 如何在 Android Oreo 中运行隐式广播?

java - Android 交互 - 音乐

java - GridLayout 呈现方式与预览方式不同

android - 在一项 Activity 中需要显示 3 个 Bottom Sheet

android - 为什么我不能从 GraphRequest 中获取用户的名字?

android - 使用新版ADT

android - 方向改变时视频不会调整大小

java - 在 Android 应用程序中使用处理程序的 ProgressBar 倒计时

android Activity 切换方向