问题
I'm tryng to implement in-app-billing.
When i follow the tutorial and add the lines bellow to my app:
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
i receive the following error:
Error:(216, 45) error: unreported exception IabAsyncInProgressException; must be caught or declared to be thrown
The strange thing is when i replace mHelper.dispose()
for mHelper.disposeWhenFinished()
it works.
I'm worried cause the same error appears again in
mHelper.launchPurchaseFlow(this,ITEM_SKU,1001,mPurchaseFinishedListener,hpacote);
Thanks
回答1:
Yes, i'm also waste a lot of time in this because in the Google Tutorial on https://developer.android.com/training/in-app-billing/preparing-iab-app.html the sample is old and buggy. If you want a right sample you have to download TrivialDrive from github https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive that has right corrections.
From TrivialDrive MainActivity:
try {
mHelper.launchPurchaseFlow(this, mSelectedSubscriptionPeriod, IabHelper.ITEM_TYPE_SUBS,oldSkus, RC_REQUEST, mPurchaseFinishedListener, payload);
} catch (IabAsyncInProgressException e) {
complain("Error launching purchase flow. Another async operation in progress.");
setWaitScreen(false);
}
and this is the onDestroy()
@Override
public void onDestroy() {
super.onDestroy();
// very important:
Log.d(TAG, "Destroying helper.");
if (mHelper != null) {
mHelper.disposeWhenFinished();
mHelper = null;
}
}
i've implemented this without error! ;)
来源:https://stackoverflow.com/questions/37027885/in-app-billing-mhelper-dispose-error