"Android Development Art Quest" Reading notes (15)--android performance optimization

Source: Internet
Author: User

"Android Development Art Exploration" reading notes (14)--jni and NDK programming

NO1:

If <include> developed this id attribute, and the root element of the included layout file also has an id attribute, the <include> specified id attribute is

No2:

Drawing optimization

1) do not create a new local object in OnDraw

2) do not take time-consuming tasks in the OnDraw method

No3:

Memory leak optimization

Scenario One: Memory leaks due to static variables:

If a static variable holds an activity, the activity cannot be released in time.

WORKAROUND: 1 Use the application context. 2 Caution with statistic keywords

Scenario Two: A memory leak caused by a singleton mode:

Because the life cycle of the singleton pattern is consistent with the application, if the singleton mode holds a activtiy, the activity cannot be released in time

Workaround: Use application's global context as much as possible.

Scenario Three: Memory leaks caused by property animations:

Because the activity view is animated, and view has activity, if the animation is infinite , the activity will not be released in time.

Workaround: Call animator.cancel() in the activity's ondestory to stop the animation

No4:

After a process has been ANR, the system creates a file traces.txtin the /data/anr directory.

NO5:

Recommendations for performance optimization

1) Avoid creating too many objects

2) do not use enumerations too much, the enumeration takes up more memory space than the shaping

3) constants, use static final to decorate

4) use some Android-specific data structures, such as Sparsearray and pair, for better performance

5) Appropriate use of soft and weak references

6) Use memory cache and disk cache

7) Use static internal classes as much as possible to avoid potential memory leaks due to internal classes

"Android Development Art Quest" Reading notes (15)--android performance optimization

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.