While Android smartphones and tablets are now running at a faster rate, developers need to keep in mind that the application's operating environment is still constrained by many resources, such as batteries and processors. Here are 10 tips on how to apply "slimming" so that you can run the best results on all of your Android devices now and in the future.
1) first of all, have good coding habits
A good developer should be good at using knowledge, perfect algorithms, and standard design patterns. To have the resource consciousness, open the need to remember to close, as far as possible late acquisition, early release. These long-standing coding guidelines also apply to Android application development, especially when using basic device services.
2) let the blocking operation principle UI thread
Ensure application flexibility by using Asynctask, threading, Intentservice, and custom background services. Use the Load tool to simplify the state management of long-time loading data such as cursors. When you have a virtual run, you can't let your app lag or stop.
If an operation consumes more time and resources, cancel the operation and replace it with asynchronous processing so that the application remains responsive and the user can continue with various actions. This method applies to read-write, access to content providers, databases, and the Internet, as well as parsing and other tasks that take a long time.
3) Use the latest Android SDK version and API
Keep your app up-to-date with Android with the latest products from the Android platform. As the Android platform continues to evolve, some features may be deprecated or replaced by better features, core APIs receive bug fixes and performance improvements, and new APIs help developers write more stable applications. To understand that the best practices always change over time, smart developers should always be at the forefront of the entire platform.
4) consider using Strictmode
The new Android2.3 class Strictmode, which can be used to capture the time-consuming disk, network access, or function calls that occur in the main thread of the application, can help developers improve threading, which is the main thread-handling UI and animations become smoother when disk reads and writes and network operations. Prevent the main thread from being blocked.
5) Disable or minimize debugging before publishing
If the development cycle is long, you are likely to have some log or debug code built into your app, ensuring that these features are minimized or completely disabled before publishing.
6) ensure a simple and elegant UI layout
The simple screen is not only easy to read, but also speeds up loading. Rather than piling up too many unnecessary features on a single screen, take the time to develop an elegant user interface. The simple and elegant UI not only improves application performance, but also improves the efficiency of the user when using the app.
7) Adjust application resources to target devices
To be loaded as efficiently as possible, it is necessary to adjust the corresponding resources according to the configuration of the specific equipment, especially the picture resources. To use the package file appropriately for different devices, you can first add only the core resources that are needed to run the application, and then download the relevant content based on the specific device.
8) using the Hierachy Viewer Visual debugging tool
Hierachy Viewer can easily design, debug and adjust the interface, quickly locate problems, solve problems, and improve development efficiency.
9) using layoutopt for layout optimization
Layoutopt is a simple command-line tool that helps find unnecessary nesting of spaces and reduces layout resources, making it possible for applications to be "slim". Less space "the lower the layout level, the better the performance.
Ten) use TraceView and other Android tools for analysis
The Android SDK comes with many tools for analysis, the most popular being tranceview, a graphical tool that helps you debug and find performance resources in your app.
10 Tips for Android development