应用内结算mHelper.dispose()错误

时间:2016-05-04 12:29:31

标签: in-app-billing

我正在尝试实施应用内结算。

当我按照教程并将下面的行添加到我的应用程序时:

 public void onDestroy() {
        super.onDestroy();
        if (mHelper != null) mHelper.dispose();
        mHelper = null;

我收到以下错误:

Error:(216, 45) error: unreported exception IabAsyncInProgressException; must be caught or declared to be thrown

奇怪的是,当我为mHelper.dispose()替换mHelper.disposeWhenFinished()时,它可以正常工作。

我很担心因为

再次出现同样的错误
mHelper.launchPurchaseFlow(this,ITEM_SKU,1001,mPurchaseFinishedListener,hpacote);

由于

1 个答案:

答案 0 :(得分:4)

是的,我也浪费了很多时间,因为在https://developer.android.com/training/in-app-billing/preparing-iab-app.html的Google教程中,样本很老而且有些错误。如果你想要一个正确的样本,你必须从github https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive下载具有正确更正的TrivialDrive。

来自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);
     }

这是onDestroy()

    @Override
    public void onDestroy() {
    super.onDestroy();

    // very important:
    Log.d(TAG, "Destroying helper.");
    if (mHelper != null) {
        mHelper.disposeWhenFinished();
        mHelper = null;
    }
}

我已经毫无错误地实现了这一点! ;)