Android Question What is ANR ?

vbmundo

Well-Known Member
Licensed User
My App show today an ANR

and this Detail

B4X:
Último informe
Hoy, 12:40
Informes de esta semana
1
Informes totales
1
Versión de la aplicación
18
1
Versión de Android
Android 6.0
1
Dispositivo
P9 (HWEVA) 1

----- pid 20686 at 2016-08-24 17:37:43 -----
Cmd line: zetoox.mysql
Build fingerprint: 'HUAWEI/EVA-L09/HWEVA:6.0/HUAWEIEVA-L09/C40B131:user/release-keys'
ABI: 'arm64'
Build type: optimized
Zygote loaded classes=4078 post zygote classes=754
Intern table: 58835 strong; 171 weak
JNI: CheckJNI is off; globals=350 (plus 366 weak)
Libraries: /system/lib64/libandroid.so /system/lib64/libcompiler_rt.so /system/lib64/libfm_jni.so /system/lib64/libhwdeviceinfo.so /system/lib64/libhwtheme_jni.so /system/lib64/libjavacrypto.so /system/lib64/libjnigraphics.so /system/lib64/libmedia_jni.so /system/lib64/libwebviewchromium_loader.so libjavacore.so (10)
Heap: 17% free, 17MB/21MB; 54138 objects
Dumping cumulative Gc timings
Start Dumping histograms for 2 iterations for concurrent mark sweep
ProcessMarkStack:    Sum: 46.709ms 99% C.I. 0.004ms-32.236ms Avg: 7.784ms Max: 32.413ms
MarkConcurrentRoots:    Sum: 12.372ms 99% C.I. 0.004ms-9.754ms Avg: 3.093ms Max: 9.825ms
UpdateAndMarkImageModUnionTable:    Sum: 11.386ms 99% C.I. 3.581ms-7.805ms Avg: 5.693ms Max: 7.805ms
MarkRootsCheckpoint:    Sum: 9.900ms 99% C.I. 0.200ms-8.150ms Avg: 2.475ms Max: 8.276ms
SweepMallocSpace:    Sum: 5.921ms 99% C.I. 0.018ms-4.150ms Avg: 1.480ms Max: 4.179ms
MarkAllocStackAsLive:    Sum: 1.450ms 99% C.I. 392us-1058us Avg: 725us Max: 1058us
ScanGrayAllocSpaceObjects:    Sum: 657us 99% C.I. 0.500us-514us Avg: 164.250us Max: 514us
ReMarkRoots:    Sum: 636us 99% C.I. 78us-558us Avg: 318us Max: 558us
SweepSystemWeaks:    Sum: 522us 99% C.I. 137us-385us Avg: 261us Max: 385us
ImageModUnionClearCards:    Sum: 350us 99% C.I. 24us-186us Avg: 87.500us Max: 186us
AllocSpaceClearCards:    Sum: 339us 99% C.I. 0.333us-227us Avg: 42.375us Max: 227us
SweepLargeObjects:    Sum: 224us 99% C.I. 23us-201us Avg: 112us Max: 201us
MarkNonThreadRoots:    Sum: 198us 99% C.I. 15us-105us Avg: 49.500us Max: 105us
EnqueueFinalizerReferences:    Sum: 190us 99% C.I. 26us-164us Avg: 95us Max: 164us
SweepZygoteSpace:    Sum: 121us 99% C.I. 49us-72us Avg: 60.500us Max: 72us
ZygoteModUnionClearCards:    Sum: 88us 99% C.I. 8us-34us Avg: 22us Max: 34us
ScanGrayImageSpaceObjects:    Sum: 53us 99% C.I. 12us-41us Avg: 26.500us Max: 41us
ScanGrayZygoteSpaceObjects:    Sum: 50us 99% C.I. 15us-35us Avg: 25us Max: 35us
(Paused)ScanGrayImageSpaceObjects:    Sum: 44us 99% C.I. 10us-34us Avg: 22us Max: 34us
(Paused)ScanGrayAllocSpaceObjects:    Sum: 39us 99% C.I. 0.250us-32us Avg: 9.750us Max: 32us
RevokeAllThreadLocalAllocationStacks:    Sum: 37us 99% C.I. 6us-31us Avg: 18.500us Max: 31us
(Paused)ScopedPause:    Sum: 34us 99% C.I. 7us-27us Avg: 17us Max: 27us
(Paused)PausePhase:    Sum: 27us 99% C.I. 9us-18us Avg: 13.500us Max: 18us
ProcessReferences:    Sum: 26us 99% C.I. 4us-22us Avg: 13us Max: 22us
MarkingPhase:    Sum: 24us 99% C.I. 10us-14us Avg: 12us Max: 14us
SwapBitmaps:    Sum: 23us 99% C.I. 5us-18us Avg: 11.500us Max: 18us
InitializePhase:    Sum: 21us 99% C.I. 3us-18us Avg: 10.500us Max: 18us
ProcessCards:    Sum: 18us 99% C.I. 2us-7us Avg: 4.500us Max: 7us
PreCleanCards:    Sum: 16us 99% C.I. 3us-13us Avg: 8us Max: 13us
Sweep:    Sum: 13us 99% C.I. 3us-10us Avg: 6.500us Max: 10us
ReclaimPhase:    Sum: 12us 99% C.I. 3us-9us Avg: 6us Max: 9us
BindBitmaps:    Sum: 10us 99% C.I. 5us-5us Avg: 5us Max: 5us
(Paused)ScanGrayZygoteSpaceObjects:    Sum: 7us 99% C.I. 1us-6us Avg: 3.500us Max: 6us
RecursiveMark:    Sum: 5us 99% C.I. 1us-4us Avg: 2.500us Max: 4us
FindDefaultSpaceBitmap:    Sum: 1us 99% C.I. 250ns-1000ns Avg: 500ns Max: 1000ns
(Paused)ProcessMarkStack:    Sum: 0 99% C.I. 0ns-0ns Avg: 0ns Max: 0ns
Done Dumping histograms
concurrent mark sweep paused:    Sum: 839us 99% C.I. 133us-706us Avg: 419.500us Max: 706us
concurrent mark sweep total time: 91.722ms mean time: 45.861ms
concurrent mark sweep freed: 52435 objects with total size 4MB
concurrent mark sweep throughput: 576209/s / 51MB/s
Total time spent in GC: 91.722ms
Mean GC size throughput: 47MB/s
Mean GC object throughput: 571553 objects/s
Total number of allocations 106562
Total bytes allocated 22MB
Total bytes freed 4MB
Free memory 3MB
Free memory until GC 3MB
Free memory until OOME 366MB
Total memory 21MB
Max memory 384MB
Zygote space size 1568KB
Total mutator paused time: 839us
Total time waiting for GC to complete: 5.730us
Total GC count: 2
Total GC time: 91.722ms
Total blocking GC count: 0
Total blocking GC time: 0
Histogram of GC count per 10000 ms: 0:31,1:1
Histogram of blocking GC count per 10000 ms: 0:32

The original detail is too much long...

What I need to know about this report ?

Regards

Edit by Erel: Explanation about ANR.
 
Last edited by a moderator:

wonder

Expert
Licensed User
Longtime User
ANR's are usually caused by too much work on the main thread.
You will most likely have to delegate the problematic function / code / subroutine to a secondary thread.
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Activity_Resume
    Dim b As Boolean
    Do Until b
    Loop
End Sub

This program will compile without any problem and still cause an ANR. ;)
 
Last edited by a moderator:
Upvote 0

vbmundo

Well-Known Member
Licensed User
Code can be as large as you want, provided that it does not contain long lasting loops.

Hi JordiCP

I haven't lasting loops, I only have some MySQL stattements.

In my MAIN activity I have a "File read operation", and a Connect operation, to a MySQL Database.. then.. a single SELECT operation for some records.. (How many Databases have this Server)

Perhaps, over 169 APP installations, 1 or 2 users, have thousands of DataBases in one single Server.. but It's too strange

Thanks
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Activity_Resume
    Dim b As Boolean
    Do Until b
    Loop
End Sub

This program will compile without any problem and still cause an ANR. ;)

Thanks !!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Activity_Resume
    Dim b As Boolean
    Do Until b
    Loop
End Sub

This program will compile without any problem and still cause an ANR. ;)

Try inserting DoEvents inside the loop... can you see the difference?
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Does it make any communication on the main thread (are you disabling the NetworkOnMainThread test)?
Yes, yes.
The connection is connected/build on mainthread. The querycalls are inside a task and raises an event after they finished.

I always suggest to use a service for the communication using my lib.

Additionally i suggest to NOT use my lib in production apps as the credentials are inside the code. I suggest to use RDC.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I always suggest to use a service for the communication using my lib
This will not help. Service code is also executed on the main thread.

Making network calls on the main thread will eventually lead to ANR errors. You can use the Threading library to make the calls in the background however it can cause other errors.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

vbmundo

Well-Known Member
Licensed User
Using my (chargeable) MySQL library i guess

Yes, your library is the holy Grail, but the ANR maybe is for your lib.

You don't allow to manage a Connection Fail... I mean, if the user put the wrong credentials, or simply Server have temporary Fails... your lib hang the movil..

Maybe this 2 ANRs over 180 installations.. was for this Issue.

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Yes, yes.
The connection is connected/build on mainthread. The querycalls are inside a task and raises an event after they finished.

I always suggest to use a service for the communication using my lib.

Additionally i suggest to NOT use my lib in production apps as the credentials are inside the code. I suggest to use RDC.

In this case, the credentials are not inside the code.. the users write it.

And I have a MySQL Service with all functions and I use Callsub instead the Service and Activitys... like you I've recommended

I'm a good student.. but I need to know too much... I only know the 1 % of all.

Regards
 
Upvote 0
Top