Android In App Billing: Can't Start Launchpurchaseflow Because Launchpurchaseflow Is In Progress
Solution 1:
I believe you just have to get the updated code the the in-app billing classes and you shouldn't run into the same problem again.
Google hasn't pushed out the changes to the SDK Manager yet as far as I know. Just copy/paste the new classes into yours and you shouldn't run into the problem any longer.
Have a look at the new code changes here: https://code.google.com/p/marketbilling/source/detail?r=7ec85a9b619fc5f85023bc8125e7e6b1ab4dd69f&path=/v3/src/com/example/android/trivialdrivesample/MainActivity.java
The classes that were changed as of March 15th are: IABHelper.java, Inventory.java, SkuDetails.java and some of the MainActivity.java file
Solution 2:
I know it is kind of late contribution to the question, but I was facing the same problem today and I was calling the in App billing within a fragment, so I looked in "labHelper.java" and I saw a direct solution I believe to the problem which is ... I modified the method "void flagStartAsync(String operation)" in labHelper.java to be like the following
voidflagStartAsync(String operation) {
if (mAsyncInProgress) {
flagEndAsync();
}
if (mAsyncInProgress) thrownewIllegalStateException("Can't start async operation (" +
operation + ") because another async operation(" + mAsyncOperation + ") is in progress.");
mAsyncOperation = operation;
mAsyncInProgress = true;
logDebug("Starting async operation: " + operation);
}
I hope this would help some one out there ...
Solution 3:
For me, the best fix was to both udpate the code to the recent one (here), and do what this post suggest:
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.
The reason that updating the code wasn't enough is that I've found special cases where this bug still occurs (or at least one):
- disconnect from the Internet;
- enter your app;
- let it initialize the
IabHelper
; - connect to the Internet;
- once the device is connected, try to make a purchase.
Solution 4:
I have the same problem.
First attempt: Workaround
I downloaded the current IabHelper.java, as per jmrmb80's solution, but that didn't work. (It seems that the repo is now deprecated and we should rely upon the version supplied by Android SDK manager.) So I followed Khan's advice:
- define IabHelper.flagEndAsync() as public, and
- add
iabHelper.flagEndAsync()
beforeiabHelper.launchPurchaseFlow(...)
This seems like a blatant hack! And it may have undesirable side effects. But, it does "work"...
This seems to be a known bug: #134 and #189.
Second attempt: Fix
After further investigation, I don't think the above workaround solved my problem. I think the real solution is to override onActivityResult
in the UI thread.
Solution 5:
No need for hacky solutions. The Activity or Fragment that is requesting the purchase flow should have this:
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (billingHelper == null) return;
// Pass on the activity result to the helper for handlingif (!billingHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd// perform any handling of activity results not related to in-app// billing...super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
That's from Google's sample project, tried it on my project and it works.
Post a Comment for "Android In App Billing: Can't Start Launchpurchaseflow Because Launchpurchaseflow Is In Progress"