Android _ programming specifications and common skills, android programming skills

Source: Internet
Author: User

Android _ programming specifications and common skills, android programming skills
1. Android coding specification 1. No Chinese characters are found in java code, and a maximum of Chinese characters can appear in comments. 2. Local variable naming and static member variable naming

It can only contain letters. The first letter of a word must be in upper case and the other letters must be in lower case.

3. Constant naming

It can only contain letters and _. All letters are in uppercase. Words are separated _.

4. Name the id in layout

Naming mode: view abbreviation _ module name_view logical name

The abbreviated view details are as follows:

LayoutView: lv

RelativeView: rv

TextView: TV

ImageView: iv

ImageButton: im

Button: btn

5. Name the view variable in the activity

Naming mode: Logical name + view abbreviation

Suggestion: If the layout file is complex, we recommend that you divide layout into multiple modules. Each module defines a moduleViewHolder whose member variables contain the view

6. id naming in strings. xml

Naming mode: activity name_function module name_logic name/activity name_logic name/common _ logic name

In strings. xml, use activity name annotations to differentiate the file content.

7. Name the image in drawable

Naming mode: activity name_logical name/common _ logical name

8. styles. xml: extract the styles that are repeatedly reproduced in layout to generate general style components and place them in styles. xml; 9. use layer-list and selector10. split the image into multiple reusable images as much as possible. 11. the server can achieve this, so do not place it on the client 12. exercise caution when referencing a third-party library to avoid using a large third-party library, resulting in a large client package 13. handle global application exceptions and errors, and send the errors to the server by email 14. image. 9 processing 15. exercise caution when using static variables for interface sharing 16.Log( system name module Name Interface Name, detailed description) 17. unit Test (logical test and Interface Test) 18. do not reuse the handler of the parent class. The handler of the corresponding class should not be used by its subclass. Otherwise, the message will be generated. what conflict 19. activity in a View. onClickListener processes all logic 20. strings. use % 1 $ s in xml to enable character string wildcard 21. if multiple activities contain common UI processing, you can extract a CommonActivity and call it the common part for processing. Other activities only need to inherit it. 22. when you use button + activitgroup to implement the tab effect, use Button. setSelected (true): Make sure that the button is in the selected state, and set the current activity of activitygroup to 23 corresponding to the button. if the development is a common component, in order to avoid conflicts, add the name of the file under the drawable/layout/menu/values directory with a prefix of 24. data must be validated, such

The numeric type must have a default value if the conversion fails;

Whether the server response data is effectively judged;

25. If the same client is to be placed in different markets and the data downloaded and used in various markets must be counted

For inconsistent client-end packages, the only difference is versionname, and the APK file name is versionname.apk.

During the upgrade, you must pass your versionCode and versionName to the server. If you need to upgrade, download the apk corresponding to versionName.

About whether to force upgrade:

1). Force upgrade in any situation

2) determine the version of the user and the latest version. if the version is compatible, force upgrade; otherwise, the upgrade is optional;

26. Some buttons should avoid repeated clicks. 2. Android performance optimization 1. http uses gzip compression to set connection timeout and response timeout

Http requests can be divided into cache and non-cache based on business needs. In a network-less environment, some data is still browsed through the cached httpresponse for offline reading.

2. listview performance optimization 1) Reuse convertView

In getItemView, determine whether convertView is empty. If it is not empty, it can be reused. If you need to add listerner to the view in couvertview, the Code must be out of if (convertView = null.

2) asynchronously load images

If the item contains a webimage, it is best to load it asynchronously.

3) the image is not displayed during fast sliding.

When the list is quickly swiped (SCROLL_STATE_FLING), the image in the item or the view that consumes resources can be retrieved without being displayed. The image is in the other two States (SCROLL_STATE_IDLE and SCROLL_STATE_TOUCH_SCROLL ), the view is displayed.

4) for images asynchronously loaded in the list, if they are not within the visible range, they will be recycled in a timely manner according to certain algorithms (for example, the pictures outside the current visible range of 10 items will be recycled, or cache the image, set a size, and recycle the Image Based on the latest minimum usage principle.) 5) Avoid memory overflow with BaseAdapter

If the entity class of BaseAdapter has attributes that consume a lot of memory, it can be saved to files. To improve performance, you can cache and limit the cache size.

3. the thread pool is used, which can be divided into the Core Thread Pool and general thread pool. The time-consuming tasks such as downloading images are placed in the General thread pool to prevent time-consuming tasks from blocking the thread pool, as a result, all asynchronous tasks must wait 4. asynchronous tasks are divided into core tasks and common tasks. errors are reported only when system errors occur in the core tasks. The ui operation of asynchronous tasks must determine whether the original activity is active. 1) the main thread should not process the network; 2) the main thread should not process the database; 3) the main thread should not process the file; 5. avoid using static member variables to reference instances that consume too much resources, such as Context6. use WeakReference instead of strong references. Weak references allow you to retain references to objects and allow GC to release objects when necessary, reclaim memory. For those objects that create cheap but consume a large amount of memory, that is, you want to keep the object and use it when the application needs it. If you want GC to recycle it when necessary, you can consider using weak references. 7. Super fat Bitmap

Timely destroy (the bitmap is recycled when the onDestroy of the Activity is used by the UI component, and the RuntimeException: Canvas: trying to use a recycled bitmap android will be thrown after it is recycled immediately. graphics. bitmap) sets a certain sampling rate (sampling is not required for images provided by developers. For images uploaded by users or uncontrolled by third parties, sampling can be performed to reduce the memory occupied by images ), when returning images from the server, we recommend that you use soft references to the resid resources of the drawable image. bitmap corresponds to any type of images of other resources. If it cannot be obtained (for example, the file does not exist, or when an OutOfMemory exception is run during file reading, there should be a corresponding default image (the default image is placed in the apk and obtained through resid );

8. Ensure that the memory occupied by Cursor is promptly released, rather than waiting for GC to process. Android obviously prefers programmers to manually close the Cursor. 9. The thread is also an important source of Memory leakage. The main cause of thread Memory leakage is the uncontrollable thread lifecycle 10. if the ImageView image is from the network, perform asynchronous loading 11. during custom View development, do not write the interaction part as a thread to refresh the interface display constantly. Instead, update the interface automatically triggered Based on the TouchListener event 12. drawable

The image used by the ui component is included in the apk package. Therefore, setImageResource or setBackgroundResource is used instead of resourceid.

Note: get (getResources (), R. drawable. btn_achievement_normal) This method is converted to drawable through resid. You need to consider the recycling problem. If drawable is a private object of the object, the memory will not be released before the object is destroyed.

13. Reuse and Recycle Activity objects

Temporary activity finish in time

Set the main interface to singleTask.

Set the interface to singleTop

14. Location Information

When obtaining the user's geographic location information, turn on the GPS when you need to obtain the data, and then close it in time

15. in onResume, set the power management on this interface. In onPause, cancel the settings. 3. AndroidUI optimization. 1. layout componentization, use merge and include reuse as much as possible. 2. use styles to reuse style definitions. 3. do not overwrite the input box. number, letter, and Chinese Character Placement Problem: All numbers and letters are divided into different types. In most cases, because our input is half-width, the placeholder values of letters and numbers cannot be determined. However, once fully divided, the placeholder values of numbers and letters are the same as those of a Chinese character, in this way, the layout problem caused by placeholder can be avoided. 5. english Document Layout: When textview is automatically changed, the word integrity should be maintained. The solution is to calculate the string length, and then manually set the number of letters displayed in each line and add '\ n' 6. complex layout uses RelativeLayout7. adaptive screen, uses dp to replace pix8. uses android: layout_weight or TableLayout to create an equals layout 9. use animation-list to create an animation
What are the common methods for Android development environment and software?

Use java to develop and install an eclipse and Android SDK package

There are many methods. The installation is very popular recently and the monthly salary is more than 10 KB ..

What are the solutions for learning ANDROID programming?

Android programmers tell me what preparations I should do. By the way, they tell me how to learn to be the most efficient, learn to understand, and develop programs at will without having to follow the books.
1. in fact, the ideas between programming languages are interconnected. If you start with java, you must learn the java basics well, just like Chinese characters and Chinese characters, you don't need to learn other physical chemistry. 2. If the efficiency is improved, you can read other people's code and write more of your own code. It is best to find corresponding examples, software, and implement them by yourself. It will be a sense of accomplishment. 3. the most important thing is interest. I have encountered a problem when writing code. I spent two days and one night solving the problem. I 've been thinking about algorithms and changing methods. It's hard to stick to it if I'm not interested. technically speaking, it is absolutely necessary to learn the basic java, class, object-oriented, interface, inheritance, and when to adopt the data structure. These concepts and usage should be very familiar, instead of reading a book, you must understand and accumulate your own code and software. Is a process that takes time. The idea of programming can be integrated through writing a small software. It is recommended to start with writing a simple software, such as writing a simple computer program or reading a TXT novel online, the program has all the functions and can be used to train you in all aspects. There is no foundation like you. You certainly cannot start with the code. You don't have to worry about writing your own code. You can directly copy the code based on others' source code to see how others implement it, and then implement it without looking at the code. There is no need to stick to android or j2_based development. There will be one, all, and programming ideas are integrated. The rest is a little effort. If you are proficient in JAVA, you can learn how to add an iphone to j2_android. One or two months will allow you to develop simple programs on all three platforms. QQ: 565362315 if you have Baidu or you have studied it before, you can add it to me. If you have too many questions, don't ask me.

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.