Android Development Specification (coding + performance +ui)

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:14px">Now brings you Android development specifications, including Android encoding specifications, Android performance optimization and Android UI Optimization.<br></span></p></p><p><p><span style="font-size:14px"><strong>one, the Android Code specification</strong></span></p></p><p><p><span style="font-size:14px">Chinese is not present in 1.java code, the maximum number of comments can appear in Chinese</span></p></p><p><p><span style="font-size:14px">2. Local variable naming, static member variable naming</span></p></p><p><p><span style="font-size:14px">Can only contain letters, the first letter of a word, all uppercase, the other letters are lowercase</span></p></p><p><p><span style="font-size:14px">3. Constant naming</span></p></p><p><p><span style="font-size:14px">Can only contain letters and _, all uppercase letters, between words separated by _</span></p></p><p><p><span style="font-size:14px">Name of the ID in 4.layout</span></p></p><p><p><span style="font-size:14px">Named Mode: the logical name of the view abbreviation _ Module name _view</span></p></p><p><p><span style="font-size:14px">The details of view abbreviations are as follows</span></p></p><p><p><span style="font-size:14px">Layoutview:lv</span></p></p><p><p><span style="font-size:14px">Relativeview:rv</span></p></p><p><p><span style="font-size:14px">Textview:tv</span></p></p><p><p><span style="font-size:14px">Imageview:iv</span></p></p><p><p><span style="font-size:14px">Imagebutton:im</span></p></p><p><p><span style="font-size:14px">Button:btn</span></p></p><p><p><span style="font-size:14px">Name of view variable in 5.activity</span></p></p><p><p><span style="font-size:14px">Named Mode: logical name +view abbreviation</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">Name of ID in 6.strings.xml</span></p></p><p><p><span style="font-size:14px">Naming Pattern: Activity name _ Function Module Name _ Logical name/activity Name _ logical Name/common_ logical Name</span></p></p><p><p><span style="font-size:14px">strings.xml, use activity name comments to separate the contents of the file</span></p></p><p><p><span style="font-size:14px">Picture naming in 7.drawable</span></p></p><p><p><span style="font-size:14px">Naming Pattern: Activity name _ logical Name/common_ logical Name</span></p></p><p><p><span style="font-size:14px">7.styles.xml: the continuous style of layout is extracted from the common style generic components, put into the styles.xml;</span></p></p><p><p><span style="font-size:14px">8. Using Layer-list and Selector</span></p></p><p><p><span style="font-size:14px">9. Image as many reusable pictures as possible</span></p></p><p><p><span style="font-size:14px">10. The server can be implemented, do not put on the client</span></p></p><p><p><span style="font-size:14px">11. Refer to Third-party libraries be cautious, avoid the application of large-capacity Third-party libraries, resulting in a very large client package</span></p></p><p><p><span style="font-size:14px">12. Handle the application of global exceptions and errors and send errors to the server by mail</span></p></p><p><p><span style="font-size:14px">13.9 Processing of Pictures.</span></p></p><p><p><span style="font-size:14px">14. Use static variable mode to realize the sharing between interfaces be careful</span></p></p><p><p><span style="font-size:14px">15.Log (system Name Module name Interface name, detailed Description)</span></p></p><p><p><span style="font-size:14px">16. Unit Test (logic test, Interface Test)</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">Handle all logic in a view.onclicklistener in 18.activity</span></p></p><p><p><span style="font-size:14px">using%1 $ s in 19.strings.xml to implement string wildcard</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">23. data must be tested, such as</span></p></p><p><p><span style="font-size:14px">The character type turns the numeral type, if the conversion fails must have the default value;</span></p></p><p><p><span style="font-size:14px">Whether the service-side response data is effectively judged;</span></p></p><p><p><span style="font-size:14px"><strong>second, Android Performance optimization</strong></span></p></p><p><p><span style="font-size:14px">1.http with gzip compression, set the connection time-out and response timeout</span></p></p><p><p><span style="font-size:14px">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.</span></p></p><p><p><span style="font-size:14px">2.listview Performance Optimization</span></p></p><p><p><span style="font-size:14px">1). Multiplexing Convertview</span></p></p><p><p><span style="font-size:14px">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) {}.</span></p></p><p><p><span style="font-size:14px">2). Loading Pictures asynchronously</span></p></p><p><p><span style="font-size:14px">If the item contains webimage, it is best to load asynchronously</span></p></p><p><p><span style="font-size:14px">3). do not show pictures when sliding quickly</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">5. Try to avoid the use of static member variables to reference resources that consume too many instances, such as context</span></p></p><p><p><span style="font-size:14px">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.</span></p></p><p><p><span style="font-size:14px">7. Super Big Fat Bitmap</span></p></p><p><p><span style="font-size:14px">Timely destruction (when The activity is ondestroy, the bitmap will be recycled)</span></p></p><p><p><span style="font-size:14px">Set a certain sample rate</span></p></p><p><p><span style="font-size:14px">Clever use of soft references</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px">10. If the picture of ImageView is from the network, it is loaded asynchronously</span></p></p><p><p><span style="font-size:14px">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</span></p></p><p><p><span style="font-size:14px"><strong>third, Android UI Optimization</strong></span></p></p><p><p><span style="font-size:14px">1.layout modular, use merge and include reuse as much as possible</span></p></p><p><p><span style="font-size:14px">2. Using styles, reusing style definitions</span></p></p><p><p><span style="font-size:14px">3. Soft keyboard pop-up control, do not let it overwrite the input box</span></p></p><p><p><span style="font-size:14px">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.</span></p></p><p><p><span style="font-size:14px">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 '</span></p></p><p><p><span style="font-size:14px">6. Complex layout using relativelayout</span></p></p><p><p><span style="font-size:14px">7. Adaptive screen, using DP instead of PIX</span></p></p><p><p><span style="font-size:14px">8. Use Android:layout_weight or tablelayout to make an equal layout</span></p></p><p><p><span style="font-size:14px">9. Animating Effects with Animation-list</span></p></p><p><p><span style="font-size:14px"><strong>Recommended Reading</strong></span></p></p><p><p><span style="font-size:14px">16 of Android development experiences that increase productivity</span></p></p><p><p><span style="font-size:14px">13 Simple and useful Android development code (for Beginners)</span></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Development Specification (coding + performance +ui)</p></p></span>

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.