in-app billing mHelper.dispose() error

我的未来我决定 提交于 2019-12-14 02:23:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!