Android two common errors (ANR and FC) solutions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.