Some scenarios for Android performance optimization

Source: Internet
Author: User

Optimize heap memory allocation for Dalvik virtual machines

1) First memory aspect, can refer to Android heap memory also can define size and optimize heap memory allocation of Dalvik virtual machine

For Android platforms, the Dalvik JAVAVM used by its hosting layer has many things to optimize for its current performance, such as the possibility of manually interfering with GC processing in the development of some large-scale games or resource-consuming applications, using The Settargetheaputilization method provided by the Dalvik.system.VMRuntime class can enhance the processing efficiency of the program heap memory. Of course, the specific principle we can refer to open source Engineering, here we only say how to use:

Private final static floattarget_heap_utilization = 0.75f;

It can be called when the program OnCreate:

Vmruntime.getruntime (). Settargetheaputilization (target_heap_utilization);

2) Android heap memory can also define its own size

For some large-scale Android projects or games in the algorithm processing is not a problem, the main impact of the performance bottleneck is Android's own memory management mechanism, the mobile phone manufacturers are stingy with RAM, for the smoothness of the software, the impact of RAM on performance is very sensitive.

In addition to optimizing heap memory allocations for Dalvik virtual machines mentioned in the last Android development network, we can also enforce our own software's memory size, using the Dalvik.system.VMRuntime class provided by Dalvik to set the minimum heap memory as an example:

Private final static int cwj_heap_size = 6* 1024* 1024;

Vmruntime.getruntime (). Setminimumheapsize (Cwj_heap_size); Set minimum heap memory to 6MB size

Of course the memory crunch can also be handled by manually interfering with the GC, and we'll mention the application next time.

2, the basic type, because Java does not have the actual pointer, in the sensitive operation or the use of the NDK to complete.

Android123 Tips Game Developers, this is more interesting is that Google launched the NDK may be to help game developers, such as OpenGL ES support significantly improved, local code to manipulate the graphical interface is necessary.

3, graphic object optimization:

This is to say that the bitmap object is destroyed on Android, you can use the Recycle () method to show the GC to reclaim a bitmap object, usually for a bitmap can be used in the following way, such as

if (bitmapobject.isrecycled () ==false)//If not recycled

Bitmapobject.recycle ();

4. Handling GIF animations:

At present, the system for animation support comparison of mental retardation for general application of the transition effect can be, but for the game general art may be accustomed to the GIF method of unified processing

Currently, the Android system can only preview the first frame of the GIF, and can read resources in the GIF89 format with the help of threads and writing parsers in J2ME.

5, for most Android phones do not have too many physical keys may we need to imagine a good gesture recognition gesturedetector and gravity sensor to achieve control. Usually we have to consider the noise reduction of the error operation problem.

Some scenarios for 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.