A. Loading
Pre-loading: 1. Reflection annotation frame reflect information, in application, multithreading preload to cache. 2. Pre-loading of resources
Lazy load: 1.Fragment lazy load 2. Resource Lazy Load
Two. Caching
1. HTTP cache, elimination time
2. Picture caching, bitmap compression, LRU elimination, persistent level two cache
3. Reflection annotation frame reflect information cache to prevent multiple reflection operation
Three. Asynchronous prevent ANR
1. Avoid too many time-consuming operations on the UI thread, Intentreceiver > 10s Anr
2. Concurrent operations using read-write locks, less synchronized,android virtual machine art until Android6.0 has not been done on the Synchronized CAs optimization, and synchronized in the hotspot performance is OK.
3. Use thread pool, combine the picture asynchronous loading and so on need to open a large quantum thread to do threads reuse.
4. Cancel a task when it is not needed, such as canceling an ongoing load task when the activity is terminated.
Four. Prevent oom
1. Bitmap: Lazy load, LRU cache, Bitmap compression (according to ImageView size), block loading large image.
2. Large files, such as TXT, and so on, segmented loading.
3. Listview&gridview to do multiplexing optimization. Using Viewholder,settag
Five. View optimization
1. Optimize layout level, layout reuse, use Include,merge label.
2. Avoid excessive drawing, reduce elements, layout overlap, open debuggpu overdraw debugging, use Hierarchy Viewer. In short, it is the performance waste of the main thread caused by multiple meaningless call OnDraw, which may be the decrease of frame number.
3. OnDraw () optimization to avoid time-consuming operations such as New Paint () in OnDraw, OnDraw should only retain the necessary code.
Six Memory leaks
1.dump Memory for analysis, you can also use the Leakcanary library.
2.HashMap Avoid using the hashcode variable key
3. Handle the context object carefully because its lifecycle is managed by the framework and avoids unauthorized holding.
4. Be careful with the static variables, and clear the discarded objects stored in the static in time.
5. Immediate release of resource objects such as File,cusor,stream,socket because the JNI layer holds references to its Java layer.
6. Non-static anonymous inner class. Common in runnable and handler.
Seven. Use of the best Performance Map
1. Thread-safe Map,concurrenthashmap, which uses a segmented lock to optimize concurrent performance.
2. Using Arraymap, the space performance is high. It is not a data structure that adapts to large data, and is slower than traditional hashmap, because the lookup method is a binary, and when you delete or add data, it will adjust the space, in the use of large amounts of data, the efficiency is not obvious, less than 50%.
3. Sparsearray, the binary method plus only int as key, high performance.
The above is a small set to introduce the Android Development Performance Optimization Summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!