With the development of mobile platforms and the continuous improvement of their applications, quality becomes the key to success or failure. Users require them to choose the installed applications with fast response and good performance. If an application cannot provide excellent functions and stable user experience, such applications will be unmounted soon.
Although Android smartphones and tablets are running faster and faster, developers still need to remember that the running environment of applications is restricted by battery, processor, and many other resources. The following are ten suggestions on how to "slim down" the application, so that the best results can be achieved on all current and future Android devices.
1) first, we must have good coding habits.
A good developer should be good at using common sense, perfect algorithms and standard design patterns. To be aware of resources, you must remember to close it and try to get it late and release it early. These long-standing coding rules are also applicable to Android Application Development, especially when using basic device services.
2) Keep blocking operations away from the main UI thread
Use AsyncTask, thread, IntentService, and custom background services to ensure application flexibility. Use the loading tool to simplify the State management of long-time data loading, such as cursors. When other programs run, your application cannot be delayed or aborted.
If an operation consumes a lot of time and resources, cancel the operation and change it to asynchronous processing, so that the application can maintain the response and the user can continue to perform various operations. This method is applicable to disk read/write, access content provider, database, and Internet, as well as parsing and other tasks that take a long time.
3) use the latest Android SDK version and API
Use the latest Android products to keep your apps up to date. With the development of the Android platform, some functions may be discarded or replaced by better functions. The core API receives bug fixes and performance improvements. The new API helps developers compile more stable applications. You must understand that the best practices always change over time, and smart developers should always be at the forefront of the entire platform.
4) use StrictMode
A new StrictMode class is provided from Android 2.3, which can be used to capture the time-consuming disks, network access, or function calls that occur in the main thread of an application, and can help developers improve the program, it makes the UI and animation processed by the main thread smoother during disk read/write and network operations to prevent the main thread from being blocked.
5) Disable or minimize debugging before release
If the development cycle is long, you may have some built-in logs or debugging code in the application. Make sure that these functions are minimized or completely disabled before release.
6) Make sure that the UI layout is simple and elegant
A simple screen not only facilitates reading, but also speeds up loading. Instead of building too many unnecessary functions on a single screen, it is better to spend time developing elegant user interfaces. The simple and elegant UI not only improves the application performance, but also improves the efficiency of using the application.
7) Adjust application resources based on the target device
To be loaded as efficiently as possible, you need to adjust the corresponding resources, especially image resources, according to the configuration of specific devices. To make the application package file suitable for different devices, you can first add only the core resources required to run the application, and then download the relevant content based on the specific device.
8) use the Hierachy Viewer visual debugging tool
Hierachy Viewer allows developers to quickly locate, solve, and improve development efficiency when designing, debugging, and adjusting interfaces.
9) layoutopt for Layout Optimization
Layoutopt is a simple command line tool that helps you find unnecessary control nesting and reduce layout resources, making your application "slim ". The fewer controls and the lighter the layout, the better the performance.
10) Use Traceview and Other Android tools for analysis
The Android SDK comes with many tools for application analysis, the most popular of which is Traceview. This graphic tool can help you debug and find performance bottlenecks in applications.
Conclusion
There are many ways to improve the performance of Android applications. Some require specific algorithms, and some rely on practical debugging and performance monitoring technologies. Fortunately, the Android platform comes with a number of free utilities to help track and solve performance problems in applications.
Via Developer
(Sarah_long is for the record of Lei Feng's website. For more information, see !)