2

我试图将Blundell 的应用内购买示例中的代码集成到我自己的应用程序中,并且它几乎都能正常工作。我做了一个名为 shop.java 的活动,它有一组按钮,一个按钮对应于可以在我的应用程序中购买的每个可能的项目。如果我单击其中一个按钮,则会进行测试购买(“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。我现在按下返回按钮返回我的应用程序的主要活动。我假设调用了 shop.java 的 onDestroy 方法,但现在我收到以下错误:

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

有任何想法吗?

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

4

1 回答 1

8

初始化计费服务时,尝试为其提供应用程序上下文而不是活动上下文。利用:

getApplicationContext()
于 2012-12-23T20:39:00.233 回答