Anrs ("Application Not Responding"), meaning "app is not responding".
In the following cases, Android will report a ANR error:
– The main thread ("Event processing Thread"/"UI thread") does not respond to input events within 5 seconds
–broadcastreceiver did not complete the return within 10 seconds
Typically, the following practices can cause the ANR
1. Network operation within the main thread
2. Perform some slow disk operations within the main thread (for example, execute SQL queries that are not optimized)
The application should respond in 5 seconds or 10 seconds, otherwise the user will feel "this app is rubbish" "rotten" "Slow" ... Wait a minute
Many of the first-entry Android developers may find the word anr, what is the Android ANR? In fact, ANR is the full name of application not responding, when an application is in the long-term suspended animation of the Android system will pop up a window wrote, XXX is not responding give two buttons one for force The close one is wait.
Conditions that may trigger ANR
1. Long-time I/O processing, such as reading and writing large files, network access caused by blocking.
2. Perform time-consuming operations, Android defaults to more than 5000ms, or 5 seconds to start the ANR window, some applications may not be cached for the first time, it is time-consuming, can be splash play splash screen logo and other ways to delay loading
3. The service and Appwidget should also be aware of multi-threaded use, unless it and the activity work in different processes.
Ways to avoid ANR
1. Separate worker threads to process time-consuming content through separate thread or by using a asynctask-like approach.
2. Time-consuming operations are segmented as much as possible, using a similar state machine approach, where Symbian-like active objects will perform a complex task in a segmented manner.
3. The UI thread do not handle too much content, such as a 5MB of text, let TextView go to SetText, to know this UI operation, there is no good way to solve, so Android123 hint, encountered in the UI need to perform complex operations, You can refer to the above 2 section of the processing method mentioned.
Log status in Android is very important, if as an Android programmer can not analyze log this, is not an introduction to Android. Let's say how to handle the log file.
When will the log file be generated?
Log generation We all know, we all know through DDMS to see log, but when will produce log file? A log file is typically generated in the following situations.
1, program abnormal exit, uncaused exception
2, program forced shutdown, Force Closed (FC)
3, the program is not responding, application no Response (ANR), by the way, the general main thread more than 5 seconds? There will be a processing of ANR
4, manually generated.
Get a log file, to be divided into several paragraphs to see. The log file is very long and contains more than 10 small pieces of information, but not to be frightened, in fact he consists mainly of three blocks.
1, the system basic information, including memory, CPU, process queue, virtual memory, garbage collection and other information.
--memory INFO (/proc/meminfo)--
--cpu INFO (top-n 1-d 1-m 30-t)--
--procrank (Procrank)--
--virtual MEMORY STATS (/proc/vmstat)--
--vmalloc INFO (/proc/vmallocinfo)--
2, time information, is also our main analysis of information.
--vmalloc INFO (/proc/vmallocinfo)--
--event INFO (/proc/vmallocinfo)--
3, virtual machine information, including process, thread tracking information, which is a good place to track process and thread specific points.
--VM traces JUST Now (/data/anr/traces.txt.bugreport:2011-01-15 16:49:02)--
--VM traces at last ANR (/data/anr/traces.txt:2011-01-15 16:49:02)--
—————————————————————————————————————————————
With less gossip, I summed up the basic steps of observing the log file.
1, if it is ANR problem, search "ANR" keyword. Quickly navigate to critical event information.
2, if it is forceclosed and other abnormal exit information, search "Fatal" keyword, quickly locate the key event information.
3, after locating the critical event information, if the information is not clear, then search the application package for virtual machine information, view the specific process and thread tracking log, to locate the code.
Reference: http://www.yyz168.info/archivehttp://blog.sina.com.cn/s/blog_5f35912f0100wdh9.html
Android ANR, Force Closed (RPM)