How to trace ANR


How to trace ANR problem !

What Triggers ANR?

In Android, application responsiveness is monitored by the Activity Manager and Window Manager system services. Android will display the ANR dialog for a particular application when it detects one of the following conditions:
  • No response to an input event (e.g. key press, screen touch) within 5 seconds
  • BroadcastReceiver hasn't finished executing within 10 seconds



How to investigate an ANR 

http://stackoverflow.com/questions/704311/android-how-do-i-investigate-an-anr


An ANR happens when some long operation takes place in the "main" thread. This is the event loop thread, and if it is busy, Android cannot process any further GUI events in the application, and thus throws up an ANR dialog.
Now, in the trace you posted, the main thread seems to be doing fine, there is no problem. It is idling in the MessageQueue, waiting for another message to come in. In your case the ANR was likely a longer operation, rather than something that blocked the thread permanently, so the event thread recovered after the operation finished, and your trace went through after the ANR.
Detecting where ANRs happen is easy if it is a permanent block (deadlock acquiring some locks for instance), but harder if it's just a temporary delay. First, go over your code and look for vunerable spots and long running operations. Examples may include using sockets, locks, thread sleeps, and other blocking operations from within the event thread. You should make sure these all happen in separate threads. If nothing seems the problem, use DDMS and enable the thread view. This shows all the threads in your application similar to the trace you have. Reproduce the ANR, and refresh the main thread at the same time. That should show you precisely whats going on at the time of the ANR

--

中文相關討論

淺談ANR及如何解決分析ANR 1
淺談ANR及如何解決分析ANR 2
淺談ANR及如何解決分析ANR 3


留言

Google

本月熱門文章

水電行介紹---台北市大同區塔城街17號的富安水電行---斷垣殘壁內找到的甲級電匠師傅^^!!

熱門文章

企鵝妹/柳允進 史上最暈的TT三分鐘完整版一次看個夠

香港朋友,真的對唔住,台灣出了這種中共的幫兇!

陳昇 Bobby Chen【把悲傷留給自己 I left sadness to myself】Official Music Video

裝潢師傅貼圖來了唷

[黑金] 台南88槍擊案主犯國民黨學甲區黨部主委王文宗 也擔任統促黨幹部

新手自建監控雲最快的方式:推薦QNAP NAS 搭配QVR Pro

堅持5個月!反送中示威者六大特色 6 features of Hong Kong Anti-ELAB Protesters│老外看香港│郝毅博 Ben Hedges│新唐人電視台

香港朋友看服貿 - 嗨,我是香港人,一個CEPA的受害者。