Android in-app billing: Can't start async operation because another async operation (is in progress)

android, android-billing

Solution

A simple tricky solution

before calling purchaseItem method just add this line

  if (billingHelper != null) billingHelper.flagEndAsync();

so your code looks this way

 if (billingHelper != null) billingHelper.flagEndAsync();
 purchaseItem("android.test.purchased");

Note: don't forget to make public flagEndAsync() method in IabHelper if you call it from another package.

Problem

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?

Original source

Related problems