Google In-App Billing causing Exception

后端 未结 3 419
生来不讨喜
生来不讨喜 2021-01-06 18:06

In one of my Android apps, I\'m trying to implement a simple grab of the inventory from Google\'s In-App billing, but it keeps giving me errors at the line of



        
3条回答
  •  天涯浪人
    2021-01-06 18:40

    Great stuff from Carl. I "think" I am seeing a similar thing, though my app is crashing via:

    java.lang.IllegalStateException: IabHelper was disposed of, so it cannot be used.
    

    And it my case, rotating the device one way, then immediately back to the original orientation SOMETIMES causes this crash. Seems that there's a "window" of time where this crash "might" happen (due to the asynchronous nature of IAB like Carl explained).

    My fix

    My "fix" was to make mHelper static, and only instantiate it if (mHelper == null), and NOT destroy it in the activity's onDestroy() method. This way, once it's setup, it sticks around, and there's no need to worry about asynchronous operations (causes by device orientation) anymore.

    Not sure if this is the right fix or not, but thought I'd mention it in case it help others.

提交回复
热议问题