Yang Master (ID: CY_YANG_DA_YE) is a developer and sharer focusing on the Android field.
Performance optimization for Android
With the development of Android applications, more and more people start to download and use the APP. For different mobile phones and different users, the experience of using the APP can be said to be the most important criterion to determine whether a user will continue to use the APP.
Such as:
- Mobile phone APP usage is becoming more and more slow
- The phone is hot for no reason
- Network problem, content can not load out
- Cell phones die fast
To improve the user experience, we have to optimize the performance of Android applications.
When there is a good improvement in performance optimization, the product experience of Android applications can be greatly improved. At the same time, in the face of a variety of competing products, the better the user experience, the more “picky” users will be attracted.
So what can we learn from this article that we can optimize? What are the metrics of performance optimization? What are the tools for performance optimization?
Something worth optimizing
Before, we introduced the importance of performance optimization, so let’s talk about which areas are likely to cause performance optimization, only when we know which areas are likely to cause performance problems, we can more targeted optimization.
- Cold start time
- Improper use of the third party SDK
- Whether the code is frequently called to create new instances
- Whether there is a transition drawing problem in APP
- Application listening, whether the broadcast is turned off
- Memory leaks caused by non-static internal classes such as Handler, Observer, and AsyncTask
- IO operations complete without closing the place
- Improper network requests cause power consumption problems
- Background service resident causes power consumption problems
Performance optimization process
At the end of the day, you have problems and you have to figure out how to solve them.
When solving a problem, use data as often as possible, and have as many tests as possible to verify the problem. Many problems are difficult to reproduce in phones with good performance and high configuration, so we can select some devices with low configuration for testing. For performance improvement, we must also ensure the stability of the Android application, not because of improving one problem to cause other problems.
Locate the problem Locate the problem Rectify the problem Rectify the problem verify the problemCopy the code
This is also a common process we use to solve bugs.
Performance optimization symptoms, causes, and tools.
performance | The phenomenon of | cause | Detection tools |
---|---|---|---|
Cold start speed | Black, white screen, the first frame appears slowly | Complex layout, main thread blocking, overdrawing, too much initialization | Hiearchy Viewer, StrictMode, TraceView, Hugo |
fluency | Application of caton | Overdrawing, main thread blocking, phone memory insufficient, GC exception | StrictMode, TraceView, Hugo |
memory | The machine is slow | Excessive memory usage causes memory leakage. Procedure | Leakcanary |
Power consumption | It gets hot and loses power quickly | Hardware continues to work under high load, frequent network access, frequent interface refresh, long time off standby, and background services continue to work | Android Studio developer options |
To solve the direction
Speed of cold start
According to Nimbledroid, the average cold startup time of an APP is less than 3 seconds, and even faster is less than 2 seconds. Causes of slow cold start
Solution: Remove Window background, add a startup background, remove complex layouts such as Merge, ViewStub, space, CoordinatorLayout
Problem: UI blocking solution: Enable child threads such as AsyncTack, HandlerThread, IntentService, ThreadPool
Fluency optimization
Solution: Remove Window background, add a startup background, remove complex layouts such as Merge, ViewStub, space, CoordinatorLayout
Problem: UI blocking solution: Enable child threads such as AsyncTack, HandlerThread, IntentService, ThreadPool
Solution: Memory leak optimization (non-static internal class, static code check, system SDK leak)
Problem: Large memory solution: cache reasonably, compress the image, and put the image in a reasonable location
Optimize the power consumption
Problem: Frequent network request solution: Network request merge, improve network request policy
Problem: Frequent interface refreshes Solution: appropriate caching, triggered response refreshes
Problem: Long time idle Solution: Use WakeLock properly and disable Service
Problem: background continuous work solution: system optimization
The last
If you have any questions, feel free to leave comments for discussion. I will reply as soon as I see it.