Android应用内结算:由于其他异步操作(正在进行中),因此无法启动异步操作 [英] Android in-app billing: Can't start async operation because another async operation (is in progress)

查看:146
本文介绍了Android应用内结算:由于其他异步操作(正在进行中),因此无法启动异步操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google教程推荐的IabHelper实用工具类,但遭到此错误的打击很大.显然,IabHelper不能同时运行多个异步操作.我什至设法通过在仍在进行盘点的同时尝试开始购买来实现目标.

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.

我已经按照建议的此处在主类中尝试实现onActivityResult,但是我在错误出现之前,甚至不要调用该方法.然后我发现了这个,但是我不知道在哪里可以找到这个flagEndAsync方法-它不是在IabHelper类中.

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.

现在,我正在寻找解决此问题的方法(而无需重新实现整个效果).我能想到的唯一解决方案是创建一个布尔字段asyncActive,该字段在启动异步任务之前已检查,如果有另一个任务处于活动状态,则不执行此操作.但这还有许多其他问题,并且不适用于所有活动.另外,我更希望异步任务队列排队并在允许的情况下尽快运行,而不是根本不运行.

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?

推荐答案

一个简单的棘手解决方案

A simple tricky solution

在调用 purchaseItem 方法之前,只需添加此行

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");

注意:如果您从另一个包中调用它,请不要忘记在IabHelper中公开public flagEndAsync()方法.

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

这篇关于Android应用内结算:由于其他异步操作(正在进行中),因此无法启动异步操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆