1

I have changed over to Google billing client 4.0 library. Since then when purchase is completed, my ui elements updates does not work.

I was trying to check if they are not in UThread anymore or something, but it is not working properly still.

billingClient!!.acknowledgePurchase(
                            acknowledgePurchaseParams
                        ) { billingResult ->
                            if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
                                saveSubscription(purchase.purchaseToken, sku)
                                mainAct?.runOnUiThread {
                                Toast.makeText(context , "Vásárlás sikeres", Toast.LENGTH_SHORT)
                                        .show()
                                delegate?.purchaseSuccess(
                                        actProduct,
                                        prevProduct,
                                        purchase.purchaseToken
                                    )
                                }
                            }
                        }

When the acknowledge is done, my UI elements should be updated. There is a menu item should be enabled and in the purchase page a textfield should show that the item is purchased. The code is running, but the UI elements are not updated.

Once I move to a different fragment, the menu item turns to enabled, so it seems to me that somehow the UI is not refreshed.

In the code mainAct is the context to the MainActivity.

Any idea?

The code was running properly on Billing library 3.0.3 and runOnUIThread was not needed at all.

Still getting weird behaviour with this library. I was setting up the billing at the same time as my users log in to the app and go from the login page to the first fragment. This fragment has a recyclerview and this recycler view was filled with data from the web. The recycler view was randomly not showing the elements, even if they were loaded and the adapter was properly updated.

One you moved to another fragment and back the recycler view was showing the data properly.

As I said, the first time call when the billing server is approached the UIThread is messed up and even if data labels or menus are updated, the updates were not showed.

So something is definitely wrong with this library.

Any idea?

Endre Olah
  • 875
  • 2
  • 9
  • 25

1 Answers1

1

This behaviour is a bit weird. The documentation is saying the most of the billing library functions can be run from any thread. Only few needs to be run on UIThread. AcknowlegdePurchase should be running on AnyThread.

I have put the Toasts into runOnUIThread and the inside the delegate functions all commands I have also put inside a runOnUIThread closure.

Now it works as on billing library 3.0.3. But the documentation was not telling anything about any of these changes, so it is really unclear, why the behaviour has changed that much between the two libraries.

Endre Olah
  • 875
  • 2
  • 9
  • 25