IInAppBillingService陷入购买重叠

时间:2017-09-21 09:36:47

标签: java android in-app-purchase android-inapp-purchase

我有InAppPurchases,我用

创建了服务
mService = IInAppBillingService.Stub.asInterface(service);

并将其与

绑定
Intent serviceIntent =
                new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);

然后我开始用

购买
JSONObject jsonObject = new JSONObject();
            jsonObject.put("android_id", MainApplication.getInstance().android_id);
            jsonObject.put("user_id", userId);
            jsonObject.put("email", userEmail);

            Bundle buyIntentBundle = mService.getBuyIntent(3, context.getPackageName(),
                    purchasingItemId, "inapp", jsonObject.toString());
            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

            if (pendingIntent != null) {
                fragmentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                        MainApplication.ACTIVITY_RESULT_REQUEST_KEY.IN_APP_BILLING_PURHASING_RESPONSE,
                        new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                        Integer.valueOf(0));
            }

它工作正常,我看到带有预加载器的白卡 - 然后购买信息,点击ok,再次看到带有预加载器的白卡,然后看到带有Purchase successful的白卡,但是如果我最小化的话应用程序之前,我会看到购买信息或Purchase successful(当预加载器旋转时)然后再打开它 - 我看到无限预加载器没有任何反应,后退按钮不起作用(但购买成功并且用户得到他的背景中的项目)和唯一的方法来摆脱它 - 是重新启动应用程序

它的外观 - https://imgur.com/II9GoSl

为什么会发生这种情况以及如何避免它?

1 个答案:

答案 0 :(得分:0)

这是一个可能的解决方案:

InAppPurchase控制器中添加一个标记,用于启动您的应用内购买意图

public volatile boolean inAppFragmentOpened = false;

并在发送意图之前将其设置为true,并在购买结束时将其设置为false

然后,在Activity的方法onStart()中添加此检查

    if (InAppBillingFacade.getInstance().inAppFragmentOpened) {
        InAppBillingFacade.getInstance().inAppFragmentOpened = false;
        Intent i = new Intent(this, MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
    }

如果开始时有一个打开的In-App purchase窗口,这会重新启动你的应用程序 - 它可以帮助避免故障和冻结,但是,或许有人知道更好的解决方案吗?