Android Encoding Specification
- The Java code does not appear in Chinese, the most comments can appear in Chinese;
- Local variable name, static member variable name: can only contain letters, the first letter of a word is uppercase, the other letters are lowercase;
- Constant naming: can only contain letters and , letters all uppercase, between words separated;
- ID naming in Layout: named mode: View abbreviation _ module name _view The logical name of view the abbreviated details are as follows Linearlayout:ll RELATIVELAYOUT:RL TEXTVIEW:TV Imageview:iv Imagebutton:ib button:btn
- The view variable naming pattern in activity is: view abbreviation + logical name suggestion: If the layout file is complex, it is recommended that layout be divided into modules, each module defines a moduleviewholder, and its member variables contain the view
- ID naming in Strings.xml: Naming pattern: Activity name function module name logical name Activity name logical name common logical name Strings.xml, use activity name comments to separate the contents of the file
- Picture naming pattern in drawable: Activity name logical name/common logical name 7. Styles.xml: The continuous style of layout is extracted from the common style generic components, put into the styles.xml;
- Using Layer-list and Selector
- Picture as many reusable pictures as possible
- Server can be implemented, do not put on the client
- Reference third-party libraries be cautious, avoid the application of large-capacity third-party libraries, resulting in a very large client package
- Handles the application of global exceptions and errors, sending errors to the server in the form of a message
- The. 9 Processing of the picture
- Using static variables to realize sharing between interfaces is prudent
- Log (System name Module name Interface name, detailed description)
- Unit Testing (logic test, Interface test)
- Do not reuse the handler of the parent class, and the handler of a class should not be used for its subclasses, or it will cause message.what conflicts
- The activity handles all the logic in a View.onclicklistener
- Using%1 $ s in Strings.xml to implement string wildcard
- If multiple activity contains common UI processing, then a commonactivity can be refined, the common part is called by it, and the rest of the activity inherits it.
- When you use Button+activitgroup to implement the tab effect, use button.setselected (true) to ensure that the button is selected and that the current activity for activitygroup corresponds to that button
- If you are developing a generic component, to avoid conflicts, add a prefix to the file name under the Drawable/layout/menu/values directory
- Data must be validated, such as character-to-digital type, if the conversion fails to have a default value, the service-side response data is valid judgment;
Android Performance optimization
- HTTP with gzip compression, set connection timeout and response time-out time HTTP requests are divided into whether they can be cached and not cacheable according to business requirements, so in a network-free environment, some data is still browsed through the cached HttpResponse, enabling offline reading.
- ListView Performance Optimization
- Multiplexing Convertview in Getitemview, determines whether the Convertview is empty, if not empty, can be reused. If the view in Couvertview needs to add Listerner, the code must be outside the if (Convertview==null) {}.
- Asynchronously loading a picture if the item contains Webimage, it is best to load asynchronously
- Do not display a picture when you swipe quickly (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
- Using 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
- 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
- Try to avoid static member variables referencing resources that are consuming too many instances, such as context
- 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.
- Super Big Fat Bitmap timely destruction (activity of OnDestroy, will bitmap recycle) set a certain sampling rate clever use of soft reference drawable corresponding Resid resources, bitmap corresponding to other resources 8. Ensure cursor The memory consumed 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
- Threads are 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
- If the ImageView picture is from the network, it is loaded asynchronously
- 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
Android UI Optimizer
- Layout component, using merge and include reuse as much as possible
- Using styles, reusing style definitions
- Soft keyboard pop-up control, do not let it overwrite the input box
- Number, letter, and character blending placeholder problems: 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.
- 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 '
- Complex layouts using relativelayout
- Adaptive screen, using DP instead of PIX
- Use Android:layout_weight or tablelayout to make an equal layout
- animating effects with Animation-list
Some other Android development suggestions
- Keep up with the pace of the Times, replace Eclipse with Android Studio, change svn to Git, which is certainly appropriate for the project development properties, git learning Chinese site: https://git-scm.com/book/v2zh/v2
- Diligence to do a summary, recommend the use of the impression notes, some understand the experience summed up, not understand the article hanging inside, there is time to slowly digest;
- Regular code review, constantly iterative, you will always find some unreasonable codes, or need to optimize the place.
- Focus on some well-known technology Big V or website, there are many things worth your digestion, recommended: Android Open source project collection, Http://tech.meituan.com/,stormzhang, but always return to the Android website or refer to a copy of Java The API documentation is boring, but you'll make a lot of progress when you're familiar with it.
- For a more in-depth look at the articles you can read: Android application development and deep analysis of design ideas behind it
- If your company does not have a strong test team, it is best to put the application on the test platform before releasing the application, such as cloud measurement;
- Take the application package name should not be too easy to repeat, if the same phone already has the package name, then the signature will cause the installation is not, it is also strange in the national security market too much, can not be like Google Play as the package name audit.
Original link: https://github.com/GeniusVJR/Good-Android-development-habits
Android Development Habits