Android Performance Optimization--anr

Source: Internet
Author: User

One, ANR (application not responding) (responsiveness by Activity Manager and window manager monitoring) classification

Service Timeout 20s

Broadcastqueue Timeout 10s

Input dispatching 5s

Second, the cause of the ANR

The main thread has done some time-consuming work

The main thread is locked by another thread (the resources required by the main thread are being used by other threads)

CPU is occupied by other processes

Third, how to solve the ANR

1. Main thread read data (main thread can not get network data, can get local data)

Tip:sharepreference commit ()/apply ()//Do not submit data using commit () in the main thread

2. Do not take time-consuming action in the Broadcastreceive OnReceive () method

Thread/intentservice Increase Priority

There should be too much time-consuming operation in the life cycle function of 3.Activity

Iv. ANR Monitoring-third party open Source Library Watchdog-anr

1. Create a monitoring thread

2. The thread continues to post a task to the UI thread (i++)

3. Fixed time of sleep

4. Wait until the thread is back up to monitor if the Post's task is executed (same as ANR)

Android Performance Optimization--anr

Related Article

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.