I am using the IabHelper
utility classes, as recommended by Google's tutorial, and I'm being hit hard by this error. Apparently IabHelper
can not run multiple async operations at the same time. I even managed to hit it by trying to start a purchase while the inventory taking was still in progress.
I have already tried to implement onActivityResult
in my main class as suggested here, but I don't even get a call to that method before the error hits. Then I found this but I have no idea where to find this flagEndAsync
method - it's not in the IabHelper
class.
Now I'm looking for a way around this (without reimplementing the whole she-bang). The only solution I can think of is to create a boolean field asyncActive
that is checked before an async task is started, and not do it if there is another task active. But that has many other problems, and doesn't work across activities. Also I'd prefer to have an async task queue up and run as soon as it's allowed to, instead of not running at all.
Any solutions for this issue?
This was not easy to crack but I found the needed workarounds. Quite disappointed with Google lately, their Android web sites have become a mess (very hard to find useful info) and their sample code is poor. When I was doing some Android development a few years ago it all went so much easier! This is yet another example of that...
Indeed IabUtil is buggy, it does not properly call off its own async tasks. The complete set of necessary workarounds to stabilise this thing:
1) make method
flagEndAsync
public. It is there, just not visible.2) have every listener call
iabHelper.flagEndAsync
to make sure the procedure is marked finished properly; it seems to be needed in all listeners.3) surround calls with a
try/catch
to catch theIllegalStateException
which may occur, and handle it that way.Find
flagEndAsync()
insideIabHelper.java
file and make it public function .Before trying purchase call
flagEndAsync()
for yourIabHelper
.you must do somthig like this code :
Really annoying issue. Here is a quick and dirty solution that is not perfect code wise, but that is user friendly and avoids bad ratings and crashes:
This way the user just has to tap another time (2 times at worst) and gets the billing popup
Hope it helps
Make sure that you call the IabHelper's
handleActivityResult
in the Activity'sonActivityResult
, and NOT in the Fragment'sonActivityResult
.The following code snippet is from TrivialDrive's MainActivity:
Update:
Or, you can get the latest IabHelper.java file here: https://code.google.com/p/marketbilling/source/browse/
The March 15th version fixed this for me. (Note other files with no changes were committed on the 15th)
I still had to fix one crash that happened during testing caused by a null intent extras when "android.test.canceled" was the sent SKU. I changed:
to:
Yes, i am also facing this issue but i resolved this but i resolved using
The above method stop all the flags. Its work for me must check