I\'ve been struggling with Android IAB v3 for a while now. I have it working consistently on my test devices. However, my crash reporting service shows two recurring crashes: on
The first IllegalStateException
is occurring because the previously launched operation using IAB Helper is yet to complete.
Probable causes:
mHelper.dispose()
in onDestroy()
of activity.In your case you are trying to query inventory when already a launchPurchase is progress.
Solution:
The status of async operation is reflected in variable mAsyncInProgress
in IabHelper
. You will have to change the scope of the variable to public
, it package by default. You can then take either of the two approaches after querying the variable:
Make sure you have called mHelper.dispose()
in onDestroy()
of activity.
or
The exception is thrown in flagStartAsync
function.
To figure our the root cause of the NullPointerException
you will have to provide the code for launchPurchasFlow with line numbers.
Other precautions you should take:
To avoid "IAB helper is not set up. Can't perform operation:launchPurchaseFlow which is caused when you call launchPurchaseFlow
before IabHelper setup is complete.
You can disable the buy button by default. Enable the button on onIabSetupFinished
callback of the IabHelper. Therefore the button will work only when the IabHelper setup is complete.