Android Performance optimization

Source: Internet
Author: User
<span id="Label3"></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><strong>one, the Android Code specification</strong></p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Chinese is not present in 1.java code, the maximum number of comments can appear in Chinese</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">2. Local variable naming, static member variable naming</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Can only contain letters, the first letter of a word, all uppercase, the other letters are lowercase</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">3. Constant naming</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Can only contain letters and _, all uppercase letters, between words separated by _</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Name of the ID in 4.layout</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Named Mode: the logical name of the view abbreviation _ Module name _view</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">The details of view abbreviations are as follows</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Layoutview:lv</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Relativeview:rv</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Textview:tv</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Imageview:iv</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Imagebutton:im</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Button:btn</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Name of view variable in 5.activity</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Named Mode: logical name +view abbreviation</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">recommendation: If the layout file is complex, It is recommended that layout be divided into modules, each of which defines a moduleviewholder whose member variables contain the view</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Name of ID in 6.strings.xml</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Naming Pattern: Activity name _ Function Module Name _ Logical name/activity Name _ logical Name/common_ logical Name</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">strings.xml, use activity name comments to separate the contents of the file</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Picture naming in 7.drawable</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Naming Pattern: Activity name _ logical Name/common_ logical Name</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">7.styles.xml: the continuous style of layout is extracted from the common style generic components, put into the styles.xml;</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">8. Using Layer-list and Selector</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">9. Image as many reusable pictures as possible</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">10. The server can be implemented, do not put on the client</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">11. Refer to Third-party libraries be cautious, avoid the application of large-capacity Third-party libraries, resulting in a very large client package</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">12. Handle the application of global exceptions and errors and send errors to the server by mail</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">13.9 Processing of Pictures.</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">14. Use static variable mode to realize the sharing between interfaces be careful</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">15.Log (system Name Module name Interface name, detailed Description)</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">16. Unit Test (logic test, Interface Test)</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">17. do not reuse the handler of the parent class, the handler of a class should not be used for its subclasses, or it will cause message.what conflicts</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Handle all logic in a view.onclicklistener in 18.activity</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">using%1 $ s in 19.strings.xml to implement string wildcard</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">20. If more than one activity contains common UI processing, you can refine a commonactivity, call the generic part to handle it, and other activity just inherit it</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">21. when using Button+activitgroup to implement the tab effect, use button.setselected (true) to ensure that the button is selected and that the current activity of activitygroup corresponds</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">22. If you are developing a generic component, to avoid conflicts, add a prefix to the file name in the Drawable/layout/menu/values directory</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">23. data must be tested, such as</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">The character type turns the numeral type, if the conversion fails must have the default value;</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Whether the service-side response data is effectively judged;</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">  <strong>second, Android Performance optimization</strong></p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">1.http with gzip compression, set the connection time-out and response timeout</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">The HTTP request is divided into whether it can be cached and not cacheable according to the business demand, then, in the Network-free environment, the cached HttpResponse is still used to browse some data and realize offline Reading.</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">2.listview Performance Optimization</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">1). Multiplexing Convertview</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">In getitemview, determine if the Convertview is empty, and if it is not empty, it can be reused. If the view in Couvertview needs to add listerner, the code must be outside the IF (convertview==null) {}.</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">2). Loading Pictures asynchronously</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">If the item contains webimage, it is best to load asynchronously</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">3). do not show pictures when sliding quickly</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">When a quick slide list (scroll_state_fling), the picture in item or the view that needs to consume resources, can not be displayed, but in the other two states (scroll_state_idle and Scroll_state_touch_ SCROLL), The view is displayed</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">3. Use a thread pool, divided into core thread pool and normal thread pool, download pictures and other time-consuming tasks placed in the normal thread pool, to avoid time-consuming tasks blocking the thread pool, resulting in all asynchronous tasks must wait</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">4. Asynchronous tasks, divided into core tasks and common tasks, only the core tasks in the System-level errors will be error, the UI operation of the asynchronous task needs to determine whether the original activity is active</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">5. Try to avoid the use of static member variables to reference resources that consume too many instances, such as context</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">6. Using WeakReference instead of a strong reference, a weak reference allows you to keep a reference to the object while allowing the GC to release the object and reclaim memory if Necessary. Consider using weak references for those objects that create inexpensive but expensive memory, want to keep the object, and use it when the application needs it, while you want the GC to be recycled as Necessary.</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">7. Super Big Fat Bitmap</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Timely destruction (when The activity is ondestroy, the bitmap will be recycled)</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Set a certain sample rate</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">Clever use of soft references</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">drawable corresponding to Resid resources, bitmap corresponding to other resources 8. Ensure that the memory that the cursor occupies is released in a timely manner, rather than waiting for the GC to handle it. And Android is obviously prone to programmers manually close the cursor off</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">9. Threading is also an important source of memory leaks. The main reason for a thread's memory leak is that the thread life cycle is not controllable</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">10. If the picture of ImageView is from the network, it is loaded asynchronously</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">11. In the application development of custom view, the interactive part, do not write thread constantly refresh the interface display, but based on the Touchlistener event active trigger interface update</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">  <strong>third, Android UI Optimization</strong></p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">1.layout modular, use merge and include reuse as much as possible</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">2. Using styles, reusing style definitions</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">3. Soft keyboard pop-up control, do not let it overwrite the input box</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">4. number, letter, and character mix placeholder problem: full-width of numbers and Letters. Since most of the time our input is half-width, the placeholder for letters and numbers cannot be determined, but once full-width, the digits and the letters occupy the same position as a Chinese character, which avoids the typographical problems caused by the occupying Position.</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">5. English document Typesetting: TextView to maintain the integrity of the word when it wraps, the solution is to calculate the length of the string, and then manually set how many letters each line displays and add ' n '</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">6. Complex layout using relativelayout</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">7. Adaptive screen, using DP instead of PIX</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">8. Use Android:layout_weight or tablelayout to make an equal layout</p></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);"><p style="margin-top: 0px; margin-bottom: 0px; padding: 5px 15px; border: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: 宋体; white-space: normal; background-color: rgb(255, 255, 255);">9. Animating Effects with Animation-list</p></p><p><p><br></p></p><p><p>Android Performance optimization</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.