ANR (Activity not Respone) (no response)
Introduce the next main thread (also known as the UI thread, the main threaded)
Features: 1. Creating UI Controls
2. Updating UI control state
3. Event handling
Limitation: The main thread does not recommend events that have more than 5 seconds
Conditions to appear:
The ANR dialog box pops up when the user input event 5s does not get a response
Broadcast recipient's onreceive () execution time exceeds 10s
Solution (Principle):
All possible time-consuming operations are performed in the child thread ()
Common time-consuming operations:
I/O: network operation
SDcard
Data operations
FC (Force Close)
Reason:
1.Error
OOM (out of memory error)
Stackoverflowerror
2.RuntimeException
Workaround:
Look at the log
The child thread cannot update the UI's workaround:
1. Send the result of the child thread execution to the main thread: Handler+massage Inter-thread communication
Send message:
Messagemsg = Mhandler. Obtainmessage (UPLOAD, JSON);
Mhandler . SendMessage (msg);
Receive Message :
Public void handlemessage (Message msg) {
Switch (msg. What) {
Case UPLOAD:
mTextView2. SetText (String) msg. obj);
break;
Case DOWNLOAD:
Mtextview. SetText (String) msg. obj);
break;
default:
break;
}
}
2. Make the update UI code snippet execute on the main thread:
1.runonuithread
2.view.post view.postdelay ()
3.handler.post handler. Postdelay ()
Reference:
Http://www.cnblogs.com/mengdd/p/3418780.html
Android two common errors (ANR and FC) solutions