Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android ANR BillingClient.queryPurchases

I am using Google billing service, version 2.0.3. Running the BillingClient.queryPurchases method in the UI thread in the activity onstart method, users sometimes encounter Application Not Responding errors like this:

THREADS:
    "main" prio=5 tid=1 TimedWaiting
      | group="main" sCount=1 dsCount=0 obj=0x73b04268 self=0xa5905400
      | sysTid=8394 nice=-4 cgrp=default sched=0/0 handle=0xa85ae534
      | state=S schedstat=( 0 0 0 ) utm=2439 stm=491 core=1 HZ=100
      | stack=0xbe437000-0xbe439000 stackSize=8MB
      | held mutexes=
      at java.lang.Object.wait! (Native method)
    - waiting on <0x05482764> (a java.lang.Object)
      at java.lang.Thread.parkFor$ (Thread.java:2127)
    - locked <0x05482764> (a java.lang.Object)
      at sun.misc.Unsafe.park (Unsafe.java:325)
      at java.util.concurrent.locks.LockSupport.parkNanos (LockSupport.java:201)
      at java.util.concurrent.FutureTask.awaitDone (FutureTask.java:418)
      at java.util.concurrent.FutureTask.get (FutureTask.java:176)
      at com.android.billingclient.api.BillingClientImpl.queryPurchases (BillingClientImpl.java:699)

What is the best way to fix this type of ANRs?

like image 835
lost000117 Avatar asked Jan 08 '20 07:01

lost000117


People also ask

What is BillingClient in Android?

↳ com.android.billingclient.api.BillingClient. Main interface for communication between the library and user application code. It provides convenience methods for in-app billing. You can create one instance of this class for your application and use it to process in-app billing operations.

What is Google Play billing?

Google Play's billing system is a service that enables you to sell digital products and content in your Android app. You can use Google Play's billing system to sell a one-time product or subscriptions on a recurring basis.

How do you acknowledge in-app purchases?

To acknowledge non-consumable purchases, use either BillingClient. acknowledgePurchase() from the Google Play Billing Library or Product. Purchases. Acknowledge from the Google Play Developer API.

What is querypurchasesasync in Android?

Use queryPurchasesAsync (String, PurchasesResponseListener) instead. Returns purchases details for currently owned items bought within your app. Only active subscriptions and non-consumed one-time purchases are returned. This method uses a cache of Google Play Store app without initiating a network request.

Is billingclient asynchronous or synchronous?

It provides synchronous (blocking) and asynchronous (non-blocking) methods for many common in-app billing operations. It's strongly recommended that you instantiate only one BillingClient instance at one time to avoid multiple PurchasesUpdatedListener.onPurchasesUpdated (BillingResult, List) callbacks for a single event.

What is the purpose of the billingclient method?

Initiates the billing flow for an in-app purchase or subscription. Initiates a flow to confirm the change of price for an item subscribed by the user. Constructs a new BillingClient.Builder instance. Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. This method is deprecated.

How do I set up a billing client?

To perform setup, call the startConnection (BillingClientStateListener) method and provide a listener; that listener will be notified when setup is complete, after which (and not before) you may start calling other methods. After setup is complete, you will typically want to request an inventory of owned items and subscriptions.


Video Answer


1 Answers

Since Version 4.0.0 of the Google Play Billing Library you can use BillingClient.queryPurchasesAsync().
BillingClient.queryPurchases() will be removed in a future release.

implementation("com.android.billingclient:billing:4.0.0")
billingClient.queryPurchasesAsync(BillingClient.SkuType.INAPP, (billingResult1, list) -> {
    ...
});
like image 101
einUsername Avatar answered Oct 22 '22 11:10

einUsername