1. Frequently changing strings are used StringBuilder, then each change with the Append method. You should not create a new String every time.
2. Use the static final variable.
3. It ' s reasonable to follow common object-oriented programming practices and has getters and setters in the public Inter Face, but within a class should always access fields directly. Only for public interface with getters and setters. For ordinary classes, you should use the public property directly.
4. The method of array traversal.
Static classFoo {intMsplat;} Foo[] Marray= ... Public voidZero () {intsum = 0; for(inti = 0; i < marray.length; ++i) {sum+=Marray[i].msplat; }} Public voidOne () {intsum = 0; Foo[] LocalArray=Marray; intLen =localarray.length; for(inti = 0; i < Len; ++i) {sum+=Localarray[i].msplat; }} Public voidBoth () {intsum = 0; for(Foo a:marray) {sum+=A.msplat; }}
The last function is the best, and the second to the bottom is a little. The first function is absolutely wrong.
5. Can avoid the overhead by declaring fields and methods accessed by inner classes to a package access, rather tha n Private access. Unfortunately this means the fields can be accessed directly by other classes in the same package so you shouldn ' t use th is in the public API. Try to avoid using the private inner class. Visibility should be visible to the package as much as possible (nothing added) rather than private.
6. You can use int as much as possible without floating-point numbers, because the cost is higher. Double and float have the same speed.
7. Call HashMap 的方法比Map 快。
Interface Aspect ***********************************************************
8. Do not nest using the weight property. Because there are many calculations to be made. Especially for components with frequently changing interfaces such as ListView和 GridView
9. Using a composite control is more efficient than using multiple controls separately. A custom component, for example, contains a TextView and a ImageView.
10. Avoid using too many previously nested layout
11. Use <include/> or<merge/> 来重用 layout。
12. For the ListView, use ViewHolder to hold the control to avoid repeating the Findviewbyid.