0

I am trying to use IN-APP purchasing but I can't deal with querySkuDetailsAsync method. All code works well but inside SkuDetailsResponseListener only the first 2 line of codes are executing, namely itemInfo and textProduct.text are executing.

 fun getProductDetails() {
    val productIds = mutableListOf<String>()
    productIds.add("product1")
    val getProductDetailQuery: SkuDetailsParams = SkuDetailsParams
        .newBuilder()
        .setSkusList(productIds)
        .setType(BillingClient.SkuType.INAPP)
        .build()

    billingClient.querySkuDetailsAsync(
        getProductDetailQuery
    ) { billingResult, list ->
        if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && list != null) {
            val itemInfo: SkuDetails = list[0]
            textProduct.text = itemInfo.title
           
            // BELOW ARE NOT EXECUTING ???
            textDesc.text = itemInfo.description
            btnPrice.text = itemInfo.price

            btnPrice.setOnClickListener {
                billingClient.launchBillingFlow(
                    this@BillingMainActivity,
                    BillingFlowParams.newBuilder()
                        .setSkuDetails(list[0])
                        .build()
                )
            }
        } else {
            val error = BillingUtils.getBillingResponses(billingResult.responseCode)
            logBilling("getProductDetails error:$error")
        }
    }

}
Ahmet B.
  • 1,290
  • 10
  • 20

1 Answers1

0

Do you use InApp-Purchases and Subscriptions? Then onSkuDetailsResponse is called perhaps twice and the second call starts during the execution of the first call. If your method is not reentrant, then it will be broken. I used synchronized onSkuDetailsResponse to solve this problem.

klausborn
  • 1
  • 1