In Android, Activity Manager and Window Manager System Services monitor the operation of each program, and the ANR prompt dialog box pops up when the program appears in the following three scenarios:
1. The user does not respond for 5 seconds after an operation has been performed.
The 2.broadCastReceiver operation was not completed within 10 seconds.
3.Service did not return the result within 20 seconds.
In the app run, it's annoying to have the ANR, which can lead to a very poor user experience. So when designing Android apps, try to avoid the ANR as much as possible. So how can we avoid the production of ANR? Just pay attention to the following three points, actually very simple:
Avoid complex time-consuming operations on the main thread, such as sending and receiving network data/doing a large number of calculations/operations database/read-write files. This can be done by using Asynctask or using multithreading.
Broadcastreceiver to perform complex operations, you can start a service in the OnReceive () method to handle
Avoid the occurrence of synchronization/deadlock or improper error handling during the design and coding phase.
How to avoid the ANR problem in Android development?