Mick
Mick

Reputation: 7937

BillingService has leaked ServiceConnection

I have attempted to integrate the code in Blundell's in-app purchasing example into my own app and its nearly all working. I have made an activity called shop.java which has a set of buttons, one for each possible item that can be purchased in my app. If I click on one of the buttons then a test purchase ("android.test.purchased") is made and appears to be carried out successfully. The log output appears reassuring:

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

control is returned to shop.java. I now press the back button to return to my apps's main activity. I presume that the shop.java's onDestroy method is called, but now I get the following error:

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

Any ideas?

EDIT: Just noticed that I get exactly the same error even if I don't attempt to purchase anything!

Upvotes: 2

Views: 1743

Answers (1)

grebulon
grebulon

Reputation: 7972

When initializing the billing service, try to give it the application context instead of the activity context. Use:

getApplicationContext()

Upvotes: 8

Related Questions