After we launched an app, there are some experience problems in the middle, one obvious is the interface lag, for this problem we have taken the following measures, has played some effect.
1. Optimize the interface level
The main tool used in this process is to combine the interface levels that can be merged to reduce the rendering of the interface, which is where the developer settings display over-rendering, where the red area must be optimized.
2. Reduce the number of UI refreshes
Reducing the number of UI refreshes is a good interface optimization, especially for collection pages such as the ListView.
"1" Use delay to reduce the interface refresh times: We have made a delay mechanism, each refresh delay 1s, when the second there is a refresh request to continue to postpone the refresh time, up to 5s when the interface must be refreshed, this effect is very obvious.
"2" before refreshing the interface to determine whether really need to refresh: For other fixed interface, we will determine whether the interface refresh, if the current display and to display the same, there is no need to refresh.
"3" Cache interface: If we want to always update the interface in the ListView, and these updates will not result in the order of the ListView, then the view will be a cache, directly to the view update.
"4" Static interface: This is a way to cache the interface, for a complex interface using the static variable cache, each time the interface is built, the static view is adjusted.
3. Interface model and data model separation
The original time we before the view display, the data model will be processed, after processing will be displayed on the interface, these processing logic should be extracted in the asynchronous thread, to generate a concrete interface model, displayed directly to show.
4. Split IO operations from the main thread
This is a concrete embodiment of 3, the operation of files, databases and other IO operations from the main thread stripped out, to avoid blocking the main thread.
5. Avoid resource competition.
Minimize the amount of resources that are generated, such as minimizing the operation of new in the program, and reasonably controlling the number of threads. When memory resource consumption is severe, garbage collection is frequently picked up and a skip frame is often present in the log.
Android Interface Optimization method