1

我有 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

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

4

1 回答 1

0

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

在控制器中添加一个标志InAppPurchase来启动您的应用内购买意图

public volatile boolean inAppFragmentOpened = false;

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

然后,在Activity's 方法中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- 它可以帮助避免故障和冻结,但是,也许有人知道更好的解决方案?

于 2017-09-27T13:26:38.027 回答