Android--android Lint Tool Project resource cleaning and detailed _android

Source: Internet
Author: User

Android--android Lint Tool Project resource cleanup

Recently maintained projects for more than two years, through the iterations of many predecessors, the project has not become robust, and become very bloated. The Android Lint tool cleans it up once, clearing out a lot of discarded layouts and resources.

1. Android Lint Tools

Can right key item, Android tools, exit clear lint markers can


You can also figure:


2. The results came out, analysis and analysis


3.xml view too much, has more than 80, affecting performance.

Layout optimization:

Try to use include, merge, viewstub tags, as far as possible there is no redundant nesting and too complex layout, as far as possible to use gone replacement invisible, use the weight after the width and heigh set to 0DP reduction operations, Item has a very complex nesting, consider using a custom item view to replace, reduce measure and layout times.

List and adapter optimization; Try to reuse the relevant view in the GetView method, do not repeatedly get the instance cause the cotton, the list as far as possible in the sliding process without UI element refresh.

Background and graphics, such as memory allocation optimization, minimize unnecessary background settings, the picture as far as possible compression processing display, as far as possible to avoid frequent memory jitter and other problems appear.

Custom view drawings and layout optimization; try to avoid too time-consuming and memory-consuming operations in draw, measure, layout, especially in the draw method, minimize the number of draw, measure, layout executions.

Avoid ANR, do time-consuming operations in the UI thread, and comply with ANR circumvention practices, such as multiple database operations.

Activity_group_number_detail1.xml has more than, bad for performance

Issue:checks whether a layout has too views

Id:toomanyviews

Using too many views in a single layout are bad for performance. Consider using compound drawables or other tricks for reducing the number of views in this layout.


4. No defined ID, delete the OK

He id ' top ' is not defined anywhere.

Issue:checks for ID references in relativelayouts that are not defined elsewhere

Id:unknownid


5. Same XML Duplicate definition ID

In the same XML file if the ID has the same name, the previous one is valid and the latter is invalid

Did you make a mistake copying and pasting?

Duplicate ID @+id/group_imageview2, already defined earlier in this layout

Issue:checks for duplicate IDs within a single layout

Id:duplicateids


The 6.ID reference is not in the same level of layout, for example, control A is under B (b is viewgroup) and should not be written as a under the child controls of B.



7. The four discarded components were not cleared out in the mainfest.xml. Delete on OK

Class referenced in the manifest, COM.BAIDU.LOCATION.F, is not found in the project or the libraries

Issue:ensures that classes referenced in the manifest are present in the project or libraries

Id:missingregistered


8. Unused resources, this is the play, to reduce the size of the packet is very meaningful. including Xml,dimens and so on. Large amount, recommend to submit SVN before deleting, if the problem can be restored immediately.

The resource r.drawable.fc_seekbar_thumb appears to be unused

Issue:looks for unused

Id:unusedresources

9. The results of the test here are only a reference, suggesting the use of toast.length_short or Toast.length_long


10. The problem of hard coding, using Context.getfilesdir (). GetPath ()

Do not HardCode "/data/"; Use Context.getfilesdir (). GetPath () instead

Issue:looks for hardcoded references To/sdcard

Id:sdcardpath

Your code should not reference The/sdcard path directly; Instead use Environment.getexternalstoragedirectory (). GetPath ().


11. Everyone can understand, viewholder problem



12.handler memory leak problem caused by

One or two words do not know, the following is already said clearly.

http://blog.csdn.net/lijunhuayc/article/details/47999931


13.webview parent control, Width height recommended with match_parent

Tips

Placing a <WebView> in a parent element that uses a wrap_content layout_height can leads to subtle
Bugs Use Match_parent instead

14.i18n's question is not to be said.

Summary: The main function of Android Lint tool is to standardize coding, optimize layout performance, and eliminate useless resources.

Thank you for reading, I hope to help you, thank you for your support for this site!


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.