android ANR BillingClient.queryPurchases
Asked Answered
S

1

6

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?

Stratosphere answered 8/1, 2020 at 7:22 Comment(5)
Thats nice! But what is your question?Monograph
I'm getting thousands of these. Did you figure out what it was?Taxpayer
Just run it in a separated Thread or AsyncTaskGrogshop
@LluisFelisart the docs of BillingClient explicitly say that the call must be made on the UI thread.Taxpayer
queryPurchasesdoes not use a listener like other BillingClient methods, if it takes a long time to execute the UI thread blocks. I call queryPurchases in a separate thread on my apps and I never had problemsGrogshop
F
1

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) -> {
    ...
});
Flabbergast answered 20/5, 2021 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.