Reputation: 2564
I am integrating Google wallet and start labHelper at the begining of buying.Normally labHelper is start at the time of activity onCreate and dispose at the time of activity onDestroy.So even though if we not using wallet service the labHelper is starting at the time of activity onCreate.
So I am trying to start labHelper at the time of starting purchase and dispose in labhelperPurchase finish listener. I am getting an Exception after purchasing.But money transefering is also happening there.
After one time purchasing , when i try to purchase second time it shows "TRANSACTION FAILED"
LabHelper Intialization
mHelper = new IabHelper(FrendyActivity.this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null)
return;
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " + result);
} else {
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
After Purchasing this is the code for dispose
mHelper.launchPurchaseFlow(FrendyActivity.this,
SkuItem, code,
mPurchaseFinishedListener, type);
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (mHelper != null)
mHelper.dispose();
mHelper = null
dealWithPurchaseSuccess(result, purchase);
}
After one time purchase, when I try to purchase the producat again am getting error the labHelper is already start
How to dispose labHelper properly after the purchase?
Upvotes: 2
Views: 175
Reputation: 8781
Simple answer: You should not dispose the iabHelper after a purchase is made. The API is not designed like that.
You should not even try to start and stop the API in methods other than onCreate and onDestroy. But if you really want it and you choose to do so create a new instance of the iabhelper first, don't reuse it.
But I suggest that you remove the dispose call in onIabPurchaseFinished and only call it in the onDestroy method.
Upvotes: 1