Performance problems detected by Android tips Tool

Source: Internet
Author: User

1. The obsoletelayoutparam tag does not work.

Invalid layout Param in a linearlayout: layout_centervertical

Issue: looks for layout Params that are not valid for the given parent Layout
ID: obsoletelayoutparam

The given layout_param is not defined for the given layout, meaning it has no effect. this usually happens when you change the parent layout or move view code around und without updating the layout Params. this will cause useless attribute processing at runtime,
And is misleading for others reading the layout so the parameter shocould be removed.

2. handlerleak non-static internal class Handler

This handler class shocould be static or leaks might occur (COM. borqs. appinstaller. appmovefragment. loadapphandler)

Issue: ensures that handler classes do not hold on to a reference to an outer class
ID: handlerleak

In Android, Handler classes shoshould be static or leaks might occur. messages enqueued on the application thread's messagequeue also retain their target handler. if the handler is an inner class, its outer class will be retained as well. to avoid leaking
Outer class, declare the handler as a static nested class with a weakreference to its outer class.

3. floatmath sometimes android has better API implementation than Java

Use Android. util. floatmath # Ceil () instead of Java. Lang. Math # Ceil to avoid argument float to double Conversion

Issue: suggests replacing java. Lang. Math callwith Android. util. floatmath to avoid Conversions
ID: floatmath

On Modern hardware, "double" is just as fast as "float" Though of course it takes more memory. however, if you are using floats and you need to compute the sine, cosine or square root, then it is better to use the android. util. floatmath class instead of Java. lang. math
Since you can call Methods written to operate on floats, so you avoid conversions back and forth to double.

Http://developer.android.com/guide/practices/design/performance.html#avoidfloat

4. inefficientweight

Use a layout_width of 0dip instead of wrap_content for better performance

Issue: looks for inefficient weight declarations in linearlayouts
ID: inefficientweight

When only a single widget in a linearlayout defines a weight, it is more efficient to assign a width/height of 0dp to it since it will absorb all the remaining space anyway. with a declared width/height of 0dp it does not have to measure its own size first.

5. nestedweights

Nested weights are bad for performance

Issue: looks for nested layout weights, which are costly
ID: nestedweights

Layout weights require a widget to be measured twice. When a linearlayout with non-zero weights is nested inside another linearlayout with non-zero weights, then the number of measurements increase exponentially.

6. unusedresources

The resource R. drawable. ic_action_search appears to be unused

Issue: looks for unused resources
ID: unusedresources

Unused resources make applications larger and slow down builds.

7. drawallocation avoid creating objects during draw and layout and call them frequently. The garbage collection operation will affect some UI experience.

Avoid object allocations during draw/layout operations (preallocate and reuse instead)

Issue: looks for memory allocations within Drawing code
ID: drawallocation

You shoshould avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations.

The way this is generally handled is to allocate the needed objects up front and to reuse them for each drawing operation.

Some methods allocate memory on your behalf (such as bitmap. Create), and these shoshould be handled in the same way.

8. usecompounddrawables

This tag and its children can be replaced by one <textview/> and a compound drawable

Issue: checks whether the current node can be replaced by a textview Using Compound drawables.
ID: usecompounddrawables

A linearlayout which contains an imageview and a textview can be more efficiently handled as a compound drawable.

There's a lint quickfix to perform this conversion in the eclipse plugin.

9. mergerootframe

This <framelayout> can be replaced with a <merge> tag

Issue: checks whether a root <framelayout> can be replaced with a <merge> tag
ID: mergerootframe

If a <framelayout> is the root of a layout and does not provide background or padding etc, it can often be replaced with a <merge> tag which is slightly more efficient. note that this depends on context, so make sure you understand how the <merge> tag works
Before proceeding.

Http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html

10. Some uselessparent layout values can be omitted.

This linearlayout layout or its framelayout parent is useless

Issue: checks whether a parent layout can be removed.
ID: uselessparent

A Layout with children that has no siblings, is not a scrollview or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy.

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.