I rewrote an app in B4A and it works great, no errors so I put it on the market (it is a free app) and got my first ever error report saying "Anr key dispatching timed out".
I researched this and found the following solution:
The app does use a webview which would come under the heading of network calls, and indeed the error report itself mentions the webview a few times.
So, is there a way I can run the webview tasks on another thread in B4A somehow as this solution suggests?
The error report itself is shown below but not being an expert I had to google a lot as I had no idea what the error meant. I only include the error message in case it helps answer my question, and because it shows the webview references I mentioned.
Please disregard the references in it to app inventor, this is a B4A app but as it replaced an appinventor one I could only publish it as an upgrade if I kept the package name the same hence the appinventor references.
The code itself works fine, I will include the apk in this post if it will help, and it is only one error report but if it is something I can correct with programming code I hope someone more experienced than I can point me in the right direction.
The error report is (for the installed apk):
Thank you for any help in advance, and apologies for the long post.
Dave
I researched this and found the following solution:
The ANR, or Application Not Responding, error occurs when a process on the main thread takes too long (something like 5 seconds). Android kills that process and any related by design to spare the device's resources.
The solution is to run resource-expensive tasks on another thread, and then post, or update the main thread accordingly. A common use for this is network calls
The app does use a webview which would come under the heading of network calls, and indeed the error report itself mentions the webview a few times.
So, is there a way I can run the webview tasks on another thread in B4A somehow as this solution suggests?
The error report itself is shown below but not being an expert I had to google a lot as I had no idea what the error meant. I only include the error message in case it helps answer my question, and because it shows the webview references I mentioned.
Please disregard the references in it to app inventor, this is a B4A app but as it replaced an appinventor one I could only publish it as an upgrade if I kept the package name the same hence the appinventor references.
The code itself works fine, I will include the apk in this post if it will help, and it is only one error report but if it is something I can correct with programming code I hope someone more experienced than I can point me in the right direction.
The error report is (for the installed apk):
B4X:
DALVIK THREADS:
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 s=N obj=0x40025b50 self=0xcdb8
| sysTid=7155 nice=0 sched=0/0 cgrp=default handle=-1345017804
| schedstat=( 952728295 799621571 1829 )
at org.apache.harmony.luni.platform.OSFileSystem.readImpl(Native Method)
at org.apache.harmony.luni.platform.OSFileSystem.read(OSFileSystem.java:118)
at java.io.FileInputStream.read(FileInputStream.java:312)
at java.io.FileInputStream.read(FileInputStream.java:267)
at anywheresoftware.b4a.phone.Phone.Shell(Phone.java:99)
at appinventor.ai_mygt_dh.Is_it_safe.main._checkscanpresent(main.java:570)
at appinventor.ai_mygt_dh.Is_it_safe.main._activity_create(main.java:339)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:99)
at appinventor.ai_mygt_dh.Is_it_safe.main.afterFirstLayout(main.java:83)
at appinventor.ai_mygt_dh.Is_it_safe.main.access$100(main.java:15)
at appinventor.ai_mygt_dh.Is_it_safe.main$WaitForLayout.run(main.java:71)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
"java.lang.ProcessManager" daemon prio=5 tid=10 NATIVE
| group="main" sCount=1 dsCount=0 s=N obj=0x472784a8 self=0x32bdc8
| sysTid=7173 nice=0 sched=0/0 cgrp=default handle=2855160
| schedstat=( 518797 3784178 12 )
at java.lang.ProcessManager.watchChildren(Native Method)
at java.lang.ProcessManager$1.run(ProcessManager.java:87)
"CookieSyncManager" prio=5 tid=9 TIMED_WAIT
| group="main" sCount=1 dsCount=0 s=N obj=0x47232908 self=0x2b9138
| sysTid=7164 nice=10 sched=0/0 cgrp=default handle=3315768
| schedstat=( 518798 3631592 5 )
at java.lang.Object.wait(Native Method)
- waiting on <0x471efd10> (a android.os.MessageQueue)
at java.lang.Object.wait(Object.java:326)
at android.os.MessageQueue.next(MessageQueue.java:142)
at android.os.Looper.loop(Looper.java:120)
at android.webkit.WebSyncManager.run(WebSyncManager.java:90)
at java.lang.Thread.run(Thread.java:1102)
"WebViewWorkerThread" prio=5 tid=8 WAIT
| group="main" sCount=1 dsCount=0 s=N obj=0x472741d8 self=0x329268
| sysTid=7162 nice=1 sched=0/0 cgrp=default handle=3314600
| schedstat=( 8087158 38146972 46 )
at java.lang.Object.wait(Native Method)
- waiting on <0x471da0e8> (a android.os.MessageQueue)
at java.lang.Object.wait(Object.java:288)
at android.os.MessageQueue.next(MessageQueue.java:146)
at android.os.Looper.loop(Looper.java:120)
at android.os.HandlerThread.run(HandlerThread.java:60)
"WebViewCoreThread" prio=5 tid=7 WAIT
| group="main" sCount=1 dsCount=0 s=N obj=0x47265360 self=0x2f0378
| sysTid=7161 nice=0 sched=0/0 cgrp=default handle=3081400
| schedstat=( 167083743 198028570 529 )
at java.lang.Object.wait(Native Method)
- waiting on <0x47265640> (a android.os.MessageQueue)
at java.lang.Object.wait(Object.java:288)
at android.os.MessageQueue.next(MessageQueue.java:146)
at android.os.Looper.loop(Looper.java:120)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:645)
at java.lang.Thread.run(Thread.java:1102)
"Binder Thread #2" prio=5 tid=6 NATIVE
| group="main" sCount=1 dsCount=0 s=N obj=0x471da458 self=0x13d488
| sysTid=7160 nice=0 sched=0/0 cgrp=default handle=1220832
| schedstat=( 3662112 11169434 19 )
at dalvik.system.NativeStart.run(Native Method)
"Binder Thread #1" prio=5 tid=5 NATIVE
| group="main" sCount=1 dsCount=0 s=N obj=0x471d9418 self=0x12ace8
| sysTid=7159 nice=0 sched=0/0 cgrp=default handle=1223832
| schedstat=( 5401609 11230471 26 )
at dalvik.system.NativeStart.run(Native Method)
"Compiler" daemon prio=5 tid=4 VMWAIT
| group="system" sCount=1 dsCount=0 s=N obj=0x471d22a8 self=0x12aaa8
| sysTid=7158 nice=0 sched=0/0 cgrp=default handle=1296024
| schedstat=( 110321031 109588633 810 )
at dalvik.system.NativeStart.run(Native Method)
"Signal Catcher" daemon prio=5 tid=3 RUNNABLE
| group="system" sCount=0 dsCount=0 s=N obj=0x471d21e8 self=0x13c558
| sysTid=7157 nice=0 sched=0/0 cgrp=default handle=1306864
| schedstat=( 1739502 8941652 8 )
at dalvik.system.NativeStart.run(Native Method)
"HeapWorker" daemon prio=5 tid=2 VMWAIT
| group="system" sCount=1 dsCount=0 s=N obj=0x45c34de0 self=0x12bb18
| sysTid=7156 nice=0 sched=0/0 cgrp=default handle=1223256
| schedstat=( 51849367 39154054 59 )
at dalvik.system.NativeStart.run(Native Method)
Thank you for any help in advance, and apologies for the long post.
Dave