Android Art-Performance optimization issues

Source: Internet
Author: User

The direction of this analysis, we mainly include: layout optimization, drawing optimization, memory leak optimization, response speed optimization, ListView optimization,Bitmap optimization, threading optimization.

Layout Optimization : Minimize the level of layout, which means There is less work to do when Android draws.

Tags:<include> 's use only supports android:layout 's Start property

<merge> can remove the extra layer of linearlayout

Viewstub inherits the View, which itself does not participate in any layout and drawing process, meaning that the required layout files are loaded on demand, and the <merge> tags are not supported .

Drawing Optimization : Refers to the onDraw method of View should avoid doing a lot of operation;

1) do not create a new layout object in OnDraw, because the OnDraw method may be called frequently, creating a large number of temporary objects in a flash, consuming too much memory and causing the system to be more frequent GC to reduce the execution efficiency of the program.

2) OnDraw do not do time-consuming tasks, excessive cycle operations will preempt The CPU time slices, which caused the View of the drawing process is not smooth. The official standard View frame rate ensures that the 60fps is the best. We need to minimize The complexity of the OnDraw method.

Memory leak Optimization : A memory leak does not cause a program to function abnormally, but it causes The memory consumption of the Android program is too large to increase the chance of memory overflow. Memory leak analysis tool MAT. We need to avoid potential memory leaks as much as possible. There will be scenarios:1. a memory leak caused by a static variable; 2. A memory leak caused by a singleton mode;3. memory leaks caused by property animations;

Response Speed Optimization: The core is to avoid time-consuming operations in the main thread and to perform time-consuming operations asynchronously. If the main thread does too much time-consuming things, it can cause Activity to start a black screen phenomenon. will lead to the emergence of ANR, after the emergence of not anxious, by analyzing the traces file can be located.

ListView and Bitmap optimizations :

the ListView optimization is nothing more than

1) adopt Viewholder and avoid Time-consuming operation in GetView;

2) control the frequency of task execution according to the sliding state of the list;

3) try to turn on hardware acceleration to be a more fluid slide of the ListView;

Bitmap optimization has been mentioned before, the main picture of the sampling,bitmapfactory.options insamplesize parameters.

Thread Optimization: The most important idea is to use a thread pool to avoid the large number of programs that exist Thread. The thread pool can reuse internal threads, thus avoiding the performance overhead of thread creation and destruction, while the thread pool can effectively control the maximum concurrency of the thread pool, avoiding the fact that a large number of counties are competing for system resources to cause blocking.

Other Optimization recommendations:1Avoid creating too many objects;2) do not use enumerations too much, they occupy more memory space than shaping;3) constant use Static final to modify;4) use soft and weak references appropriately,5) adopt memory cache and disk cache;6 ) use static internal classes as much as possible; 7 ) use some Android unique data structure.

Android Art-Performance optimization issues

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: 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.