One, the Android code specification1.java code does not appear in Chinese, most of the gaze can appear in Chinese2. Local variable naming, static member variable naming
Can only include letters, the first letter of the word out. All uppercase and lowercase for all other letters
3. Constant naming
Can only include letters and _. All uppercase letters. Separate words with _
name of the ID in 4.layout
Named mode: The logical name of the view abbreviation _ Module name _view
The abbreviation details for the view are as follows
Layoutview:lv
Relativeview:rv
Textview:tv
Imageview:iv
Imagebutton:im
Button:btn
name of view variable in 5.activity
Named mode: logical name +view abbreviation
Recommendation: Assuming the layout file is very complex, it is recommended that layout be divided into modules, each of which defines a moduleviewholder, whose member variables include the owning view
name of ID in 6.strings.xml
Naming pattern: Activity Name _ Function Module Name _ Logical name/activity name _ logical name/common_ logical name
Strings.xml, use the activity name to stare. Separating the contents of a file
picture naming in 7.drawable
Naming pattern: Activity Name _ logical name/common_ logical name
8.styles.xml: Distill The constantly reproduced style of layout into a common style generic component and put it in Styles.xml. 9. Using Layer-list and selector10. Image as many reusable pictures as possible11. The service side can achieve. Don't put it in the client .12. Refer to third-party libraries be cautious, avoid the application of large-capacity third-party libraries, resulting in a large client package13. Handle the application of global exceptions and errors and send errors to the server by mail14.9 Processing of pictures.15. Use static variables to realize the sharing between interfaces be cautious16.Log (System name Module name Interface name. Specific description of the narrative)17. Unit Test (logic test, interface test)18. Do not reuse the handler of the parent class, the handler of the corresponding class should not be used for its subclasses, otherwise it will cause message.what conflicthandle all logic in a view.onclicklistener in 19.activityusing%1 $ s in 20.strings.xml to implement string wildcard21. Assume that multiple activity includes common UI processing. It is then possible to refine a commonactivity and call the generic part to handle it, and the other activity simply inherits it .22. When using Button+activitgroup to implement the tab effect, use button.setselected (true) to ensure that the button is selected. And make the current activity of activitygroup corresponding to the button23. If you are developing a generic component, to avoid conflicts, add a prefix to the file name under the Drawable/layout/menu/values folder24. The data must be tested. Like
The character type turns the numeral type, assumes the conversion failure must have the default value;
Whether the service-side response data is valid inference;
25. The same client is assumed to be placed in a different market, and to be counted in each market to download and use data
For different clients to play different packages, the only difference is versionname. APK filename is called versionname.apk
When upgrading, you should pass your Versioncode and versionname to the server. Suppose you need to upgrade. Download the appropriate apk for Versionname
About whether you want to force an upgrade:
1). Force the upgrade in any situation
2). Infer the user's version number and current latest version number. If the compatibility is forced to upgrade, otherwise optional;
26. Some buttons to avoid repeated clicksSecond, Android performance optimization1.http with gzip compression, set the connection time-out and response timeout
HTTP requests follow business requirements. Can be divided into enough cache and non-cacheable. Then in the network-free environment, still browsing some data through the cached HttpResponse, realize the offline reading.
2.listview Performance Optimization1) Multiplexing Convertview
In the Getitemview. Infers whether the Convertview is empty, assuming that it is not empty and reusable.
Suppose the view in Couvertview needs to be added to Listerner. The code must be outside the if (Convertview==null) {}.
2) Loading images asynchronously
The item is assumed to include Webimage. Then it's best to load asynchronously
3) Do not display pictures when sliding at high speed
When a high-speed sliding list (scroll_state_fling), the picture in item or the view that needs to consume resources, can not be displayed. And in the other two states (Scroll_state_idle and Scroll_state_touch_scroll), the view is displayed
4) The list in the asynchronous loading of the picture, when not in the visual range, according to a certain algorithm in a timely manner (such as in the current visual range of the top and bottom 10 item outside the picture to recycle. Or the picture is cached. Set a size that is recycled in excess of the least recently used principle)W) Baseadapter Avoid memory overflow
Suppose Baseadapter's entity class has properties that consume memory and can be saved to a file. To improve performance, caching is possible. and limit the cache size.
3. Use the thread pool. It is divided into the core pool and the common thread pools. Time-consuming tasks such as downloading pictures are placed in a regular thread pool, avoiding time-consuming tasks blocking the thread pool, causing all asynchronous tasks to wait4. Asynchronous tasks, divided into core tasks and common tasks, only the core tasks of the system-level errors will be error, the UI operation of the asynchronous task need to infer whether the original activity is active1) The main thread does not carry on the network processing;2) do not perform database processing on the main thread. 3) The main thread does not file processing. 5. Try to avoid the use of static member variables to reference resources that consume too many instances, such as context6. Using WeakReference instead of strong references, weak references allow you to keep references to objects. At the same time, allow the GC to dispose of objects if necessary. Reclaim memory. For those who create inexpensive but memory-intensive objects, you want to keep the object and use it when the application needs it, and at the same time want the GC to be recycled when necessary. Be able to consider using weak references. 7. Super Big Fat bitmap
Timely destruction (OnDestroy of the activity will be bitmap recycled, and immediately after being used by the UI component will throw RuntimeException:Canvas:trying to use a recycled bitmap ANDROID.GRAPHICS.BITMAP) Set a certain sample rate (there is no need to sample the developer-provided images, for real user uploads or third-party size of the uncontrolled picture, can be taken to reduce the image of the memory). Return the picture from the service side, suggest that the same time the size of the feedback picture clever use soft reference drawable corresponding Resid resources, bitmap the corresponding other resources regardless of what kind of picture, assuming not get (such as the file does not exist, or read the file run OutOfMemory exception) , there should be a corresponding default picture (the default image is placed in the APK, obtained by Resid).
8. Ensure that the memory that the cursor occupies is released in a timely manner, rather than waiting for the GC to process. And Android is obviously prone to the programmer manually close the cursor off9. 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 controllable10. Assume that the ImageView image is from the network and is loaded asynchronously11. Application development in their own definition of the view, the interactive part, do not write thread constantly refresh the interface display, but based on the Touchlistener event active trigger interface update12.Drawable
The image that the UI component needs to use is the APK package that comes with it, so use Setimageresource or setbackgroundresource instead of ResourceID
Note: Get (Getresources (), R.drawable.btn_achievement_normal) This method is converted to drawable by Resid, and the issue of recycling needs to be considered. Assuming that drawable is an object private object, it is certainly not free of memory until the object is destroyed.
13. Reusing and recovering activity objects
Temporary activity in time finish
The main interface is set to Singletask
General interface set to Singletop
14. Location Information
When obtaining geo-location information for a user. Turn on the GPS when you need to get the data, then close it in time
15. Set the power management of the interface when Onresume, and cancel the setting when OnPausethird, Androidui optimization1.layout Modular, use merge and include reuse as much as possible2. Using styles, reusing style definitions3. Soft keyboard pop-up control, do not let it overwrite the input box4. Number, letter, and character mix placeholder problem: Full-width of numbers and letters.
Because in most cases our input is half-width. So the placeholder for letters and numbers cannot be determined. However, once the full-angle, the digit, the letter placeholder and a Chinese character occupies the same, so as to avoid the placeholder caused by the typesetting problem.
5. English document typesetting: TextView to maintain the integrity of the word when he is actively changing, the solution is to calculate the length of the string. Then manually set how many letters each line displays and add ' \ n '6. Complex layout using Relativelayout7. Adaptive screen, using DP instead of PIX8. Use Android:layout_weight or tablelayout to make distribution Bureau9. Animating effects with Animation-list
ANDROID_ programming specifications and frequently used techniques