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")
        }
    }

}

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.