android ANR BillingClient.queryPurchases

944 views Asked by At

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?

1

There are 1 answers

0
einUsername On

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) -> {
    ...
});