BillingService已泄露ServiceConnection

时间:2012-10-29 16:15:02

标签: android

我试图将Blundell's in-app purchasing example中的代码集成到我自己的应用程序中,几乎所有工作都可以。我做了一个名为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

有什么想法吗?

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

1 个答案:

答案 0 :(得分:7)

初始化结算服务时,请尝试为其提供应用程序上下文而不是活动上下文。使用:

getApplicationContext()