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?
queryPurchases
does not use a listener like other BillingClient methods, if it takes a long time to execute the UI thread blocks. I callqueryPurchases
in a separate thread on my apps and I never had problems – Grogshop