2012-10-29 66 views
2

我試圖將代碼Blundell's in-app purchasing example集成到我自己的應用程序中,並且它幾乎全部正常工作。我做了一個名爲shop.java的活動,它有一組按鈕,每個可能的項目都可以在我的應用程序中購買。如果我點擊其中一個按鈕,則會進行測試購買(「android.test.purchased」),並且似乎已成功執行。日誌輸出看起來讓人放心:BillingService已泄露ServiceConnection

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: [email protected] 
Stopping Service 

控制返回到shop.java。我現在按回退按鈕返回到我的應用程序的主要活動。我認爲shop.java的onDestroy方法被調用,但現在我得到以下錯誤:

Service com.mycompany.mygame.BillingService has leaked ServiceConnection [email protected] that was originally bound here 

任何想法?

編輯:只是注意到,即使我不試圖購買任何東西,我得到完全相同的錯誤!

回答

5

初始化開票服務時,嘗試給它一個應用程序上下文而不是活動上下文。使用:

getApplicationContext() 
+0

我有一個不同的問題,可能是由相同的事情引起的。謝謝,這有助於。 – Joe

+0

看起來,這對我也有詭計。 – trans

+0

changed unbindService(mServiceConn); 至 getApplicationContext()。unbindService(mServiceConn); in onDestroy() 現在完美工作:) THX! – GulBrillo

相關問題