In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge of what the development specification of Android is. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
I. Android coding specification
Chinese does not appear in 1.java code, but can appear in most comments.
two。 Local variable naming, static member variable naming
Can only contain letters, the first letter of the word is more than *, all are uppercase, and the other letters are lowercase
3. Constant naming
Can only contain letters and _, letters are all capitalized, words are separated by _
Id naming in 4.layout
The naming pattern is: view abbreviation _ module name _ logical name of view
The abbreviations of view are as follows
LayoutView:lv
RelativeView:rv
TextView:tv
ImageView:iv
ImageButton:im
Button:btn
View variable naming in 5.activity
The naming pattern is: logical name + view abbreviation
Suggestion: if the layout file is complex, it is recommended that the layout be divided into multiple modules, each module defines a moduleViewHolder, and its member variables contain the view to which it belongs.
Id naming in 6.strings.xml
Naming pattern: activity name _ function module name _ logical name / activity name _ logical name / common_ logical name
In strings.xml, use activity name annotations to distinguish the contents of the file
Picture naming in 7.drawable
Naming pattern: activity name _ logical name / common_ logical name
7.styles.xml: extract common style components from layout into general style components and put them into styles.xml
8. Using layer-list and selector
9. Try to split the picture into multiple reusable pictures
10. If the server can achieve it, don't put it on the client.
11. Be careful to quote third-party libraries to avoid applying large-capacity third-party libraries, resulting in very large client packages
twelve。 Handle application global exceptions and errors, and send errors to the server in the form of e-mail
13. .9 processing of pictures
14. It should be cautious to use static variables to realize the sharing between interfaces.
15.Log (system name module name interface name, detailed description)
16. Unit testing (logic testing, interface testing)
17. Do not reuse the handler of the parent class, and the handler of the corresponding class should not be used by its subclasses, otherwise it will lead to message.what conflicts
Handle all logic in one View.OnClickListener in 18.activity
1$ s is used in 19.strings.xml to realize the wildcard of string.
20. If multiple Activity contain common UI processing, you can extract one CommonActivity, call the general part to be handled by it, and other activity can just inherit it.
21. When using button+activitgroup for the tab effect, use Button.setSelected (true) to make sure the button is selected and make the current activity of the activitygroup correspond to the button
twenty-two。 If you are developing a generic component, to avoid conflicts, add a prefix to the file name in the drawable/layout/menu/values directory
23. Data must be validated, such as
Character type to digital type, there must be a default if the conversion fails.
Whether the response data of the server is effective or not
Second, Android performance optimization
1.http uses gzip compression to set the connection timeout and response timeout
Http requests are divided into cacheable and non-cacheable requests according to business requirements, so in a network-free environment, part of the data is still browsed through cached httpresponse to achieve offline reading.
2.listview performance optimization
1)。 Reuse convertView
In getItemView, it is determined whether the convertView is empty, and if not, it can be reused. If the view in couvertview needs to add listerner, the code must be outside of if (convertView==null) {}.
2)。 Load pictures asynchronously
If webimage is included in item, then * load asynchronously
3)。 Do not display pictures when swiping
When swiping the list (SCROLL_STATE_FLING), the picture in item or getting the view that consumes resources may not be displayed, while in the other two states (SCROLL_STATE_IDLE and SCROLL_STATE_TOUCH_SCROLL), those view will be displayed.
3. Use the thread pool, which is divided into the core thread pool and the ordinary thread pool. Time-consuming tasks such as downloading pictures are placed in the ordinary thread pool to prevent time-consuming tasks from blocking the thread pool, resulting in all asynchronous tasks having to wait
4. Asynchronous tasks are divided into core tasks and ordinary tasks. Only system-level errors in the core tasks will report errors. The ui operation of asynchronous tasks needs to determine whether the original activity is active.
5. Try to avoid static member variables referencing instances that consume too much resources, such as Context
6. Using WeakReference instead of strong references, weak references allow you to maintain references to objects while allowing GC to free objects and reclaim memory if necessary. For objects that are cheap to create but consume a lot of memory, you want to keep the object and use it when the application needs it, and consider using weak references when you want GC to recycle if necessary.
7. Bitmap, a super fat man
Destroy in time (when Activity onDestroy, bitmap will be recycled)
Set a certain sampling rate
Ingenious use of soft quotation
Drawable corresponds to the resources of resid, and bitmap corresponds to other resources. Make sure that the memory occupied by Cursor is released in time, rather than waiting for GC to deal with it. And Android obviously prefers programmers to drop Cursor close manually.
9. Threads are also an important source of memory leaks. The main reason for thread memory leakage is that the thread life cycle is uncontrollable.
10. If the picture of ImageView is from the network, load it asynchronously
11. When customizing View in application development, the interactive part must not be written as a thread to constantly refresh the interface display, but actively trigger interface updates according to TouchListener events.
III. AndroidUI optimization
1.layout groupware, using merge and include reuse as much as possible
two。 Using styles to reuse style definitions
3. The pop-up control of the soft keyboard, do not let it overwrite the input box
4. The problem of mixed arrangement of numbers, letters and Chinese characters: the full-angle of numbers and letters. Since most of our input is half-width, the occupation of letters and numbers cannot be determined, but once full-angle, the occupancy of numbers and letters is the same as that of a Chinese character. in this way, the typesetting problem caused by space occupation can be avoided.
5. English document typesetting: textview automatic line wrapping to maintain the integrity of words, the solution is to calculate the length of the string, and then manually set how many letters are displayed on each line and add'n'
6. Complex layout using RelativeLayout
7. Adaptive screen, using dp instead of pix
8. Use android:layout_weight or TableLayout production and other distribution bureau
9. Animating effects with animation-list
These are all the contents of the article "what is the development specification of Android?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.