Corporate Android Project Specifications

Source: Internet
Author: User
Tags what interface

1: Project code directory structure:

This is the entire package structure of the project, the reason for confidentiality is not posted here.

2: Naming specification:

2.1.Java code file naming specification:

A: try to use English name , the word is not abbreviated , do not use underline stitching, and take the first letter capital Stitching .

b: generic Java code files are named to inherit the name of the class name suffix, for example: Files that inherit from Activity can be written as Mainactivity.java. inheritance Adapter can be written as Userlistadapter.java.

C: Some purely class name adherence is prefixed with a large collation, which can be customized, for example: Inforank.java.

D: first letter and multiple words each word must be capitalized, not underlined.    such as Userinfo.java. do not write User_info.java.

E:The method name in theJava class begins with lowercase, if multiple words, starting with the first letter capitalized from the second word, for example: getuserlist ().

F: For the Java class member variables, to use English words, the first letter lowercase, multiple words from the beginning of the second word first uppercase stitching, do not use underline stitching. For example:Usermoney.

G: For constants in java classes , you can only include letters and _, all uppercase letters, and words separated by _ . For example: max_age.

2.2, layout file naming specification:

A: named to all lowercase, the word is not abbreviated , more than one word underlined stitching , for example:user_info_list.xml.

User_info_list_item.xml ( a sub-layout file is used when using the ListView ).

B: The name of the layout file can be referred to the name of the code file, generally a page an XML, corresponding to also have a Java code, corresponding java and XML naming can be the same. if the betrecord.java corresponds to bet_record.xml

C: For each control within the layout file naming, to follow the file name as the beginning. For example: In bet_record.xml, bounce key:@+id/bet_record_back, list @+id/bet_record_listview , determine the key

@+id/bet_record_submit, the other controls are named according to the actual meaning, for example:

Bet_record_no,bet_record_money, Ensure that the name of each control is unique throughout the project .

2.3, picture resource file naming specification:

A: named to all lowercase, the word is not abbreviated , multiple words with underline stitching .

B: The name of the image must be unique, the entire set of pictures directly stored in the drawable-hdpi folder, to name the classification.

C: Button class picture naming is prefixed with a button, such as button _ok,button_cancel.

D: The background class image is named with the b-g prefix. For example:bg_top,bg_listview.

E: Display class picture naming is prefixed with view .

F: Display class picture naming is prefixed with dis , such as slideshow playback.

G: The temporary diagram is named with the tmp prefix.

H: Other names are prefixed with other.

3. Code specification

a: all code should be aligned and neatly arranged. If there is only one line of comments, try to use // /*    */

b: activity activity activity    The    adapter and asynchronous program or other, can go out independently as far as possible. Write a class java object-oriented thinking, Makes the code more concise and clear. Easy to maintain. each class      previous comment is what function, what interface, need to receive those parameters (including the name and meaning of the representative).

C: For any method if there are several classes inside ( more than 2 times ), it should be extracted, written as a generic, to call, rather than a copy of each class. Ease of maintenance and reduced code duplication. such as counting the countdown method.

D: For the value that you want to get frequently, you should get it at the beginning, and then define a static variable, each time you call the variable, instead of reading that method every time, like getting a phone screen, getting it once, and then saving it to a static variable instead of getting the phone screen every time.

E: For the same style of control, you should extract the style, unified definition into the style.xml , like the return key, continue to buy the color button, define such a control later, only define an ID, Call the style to do so.

F: do not reuse the handlerof the parent class, and the handlerof a class should not be used for its subclasses, or it will cause Message.what conflict .

G:All controls are initialized in the activity in a Initui () method, and all listener events are set inside the initlistener () method, View.onclicklistener handles all the listening, but for the specific processing of the business logic can be written as a method, listen to the call on it.

H: The data must be tested, such as character-to-digital, if the conversion failed must have a default value. Whether the service-side response data is judged effectively. For example, if a network request returns code as "0000". All checksums are written as a validatae () method . By returning a Boolean value to determine whether to pass the checksum, do not write together with the business logic.

I: Some buttons to avoid repeated clicks. For example, network requests, after clicking on the disabled. is not released until asynchronous processing is complete.

J: For fonts are used in SP units , for height, width, indentation, etc. using dip for length units , all layouts are adaptive screen, you can choose 3.2 in Eclipse ,4.0,5.4 and so on different screens to see whether the layout is the same, whether deformation. Problems such as arranging exceptions.

K: Network loading, file processing, database processing and other issues do not put in the main site, are put in the asynchronous operation.

L: Do not use asynchronous loading and hander collocation, general use of asynchronous is possible. hander is used in conjunction with threads. In general, using asynchronous comparisons consumes resources, but is highly efficient. The use of handler is relatively inexpensive, but less efficient, and if both are used at the same time, and resources are inefficient, it is not recommended to use them together. Choose one.

M: For each object to be used in the time to judge, and then to use, to avoid because of data changes or no data caused by error. The following code can be used for reference:

1) for strings can be called function.strnotnull (str);

2) for object if (obj!=null)

3) for set function.listnotnull (list); Function.mapnotnull (map);

4) for arrays function.arraynotnull (array);

N: All static , immutable ( final) constants are written to Constantutil.java inside.

All static, variable. All that needs to be shared is written to Variateutil.java. such as screen size;

All of the common functions and methods are written to Functionutil.java. The others can be expanded.

O: For the definition of variables, can be defined as a local do not define to the global inside, so as to facilitate memory recycling. Do not use string concatenation of strings, but use stringbuffer. For loops, do not define variables in them. This can also reduce the allocation of memory. For example

Person person = null;// defined outside the loop

int size = List.size ();// avoid repeated calls

for (int i; i < size; I + +) {

person = List.get (i);

to use the person object again

}

P: For a list, if you use fewer fields, you can define multiple list<string> , but if you use more, you should define these fields as a Bean object, and then store the data in the list<bean> .

Q: It is prudent to use static variables for sharing between interfaces. Each individual class does not define a static variable inside.

.............. Pending Additions .............

Corporate Android Project Specifications

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.