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