Oyo*_*yoy 23 android android-billing
我正在测试我的账单,我得到了这个例外:
java.lang.IllegalStateException: Can't start async operation (launchPurchaseFlow) because another async operation(launchPurchaseFlow) is in progress.
at utils.IabHelper.flagStartAsync(IabHelper.java:711)
at utils.IabHelper.launchPurchaseFlow(IabHelper.java:316)
at utils.IabHelper.launchPurchaseFlow(IabHelper.java:294)
at com.problemio.SubscribeIntroActivity$6.onClick(SubscribeIntroActivity.java:117)
at android.view.View.performClick(View.java:2532)
at android.view.View$PerformClick.run(View.java:9308)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我运行此代码后:
Button subscribe = (Button)findViewById(R.id.subscribe);
subscribe.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
// FIRST CHECK IF THE USER IS ALREADY A SUBSCRIBER.
mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
}
});
Run Code Online (Sandbox Code Playgroud)
但在此之前,我将其作为测试用户运行,并使用测试产品ID,即:android.test.purchased并且它有效.但是,当我将产品ID更改为我自己的产品ID时,它会因上述异常而崩溃.
有没有想过为什么会这样?谢谢!
ash*_*hes 55
IabHelper只允许一次执行一个异步查询.您需要实现onActivityResult()并将参数传递handleActivityResult()给IabHelper 的方法.
应用内结算示例代码实现了如下方法:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.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.");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8922 次 |
| 最近记录: |