Tips for Quick Start of Android applications

Source: Internet
Author: User
The Android system framework and upper-layer applications are developed in Java (not the Orthodox Sun Java) and implement their own Java Virtual Machine Dalvik. Since Java Virtual Machine and Java are used for development, efficiency is generally considered low. In fact, Android is the fastest running speed on basically mainstream smartphone software platforms.

Why is Android efficiency so high? Especially for an applicationProgramThe startup time is very short. This article mainly analyzes the following aspects:

1. Optimized reading of resource files.

We know that android UI development has a great advantage in describing the UI in XML files, so there is a benefit that you do not need to modify the UI as long as you modify it.CodeYou can modify the layout, display style, and font size of the interface. The interface definition becomes flexible and convenient. The xml configuration UI is also used in qtopia, but it is so powerful and not widely used, because the XML file is inefficient in parsing XML.

How does Android do it?

Android optimizes XML files during compilation, and Android applications become very efficient in parsing. We can see that there will be an optimized resource file after the APK file is decompressed.

2. Optimize the DEX file during installation

Android applications are packaged into an APK file, which is actually a zip file. When the system is started for the first time or the application is installed for the first time, the system decompress the APK file, optimize the executable file Dex to the odex file, and put it in the/data/Dalvik-cache directory. The optimized Dex file starts faster. This explains why the first startup of the Android system is slow and will soon become faster.

Some may ask: why is it not directly optimized during compilation? The 5th item will answer this question.

3. Create a database

Android graphics applications load all the images in the entire SD card, but why is it so fast? In fact, Android has made the data into a database in advance, so it does not need to scan the entire SD card every time, which greatly speeds up startup.

4. Efficient virtual machines

Android is based on Java-like virtual machine Dalvik. Generally, Java virtual machines are stack-based, while Dalvik is based on registers. In fact, I do not know much about the differences between the two, but I have a special online analysis of relevant literature. My simple understanding is that the stack implementation method is relatively easy. The relevant data is in the memory stack, and the data speed in the Operation register is significantly faster than the data processing in the memory.

5. Fully explore CPU Performance

Although Android supports arm cpu when it first came out, it actually only supports armv5te instruction sets. Because the Android system is specially optimized for armv5te, it makes full use of the execution pipeline of armv5te to improve the execution efficiency, this is also the reason why 2440 M Samsung does not work well, and m omap cpu runs smoothly, therefore, the latest Code provides Optimization for x86 and armv4.

6. Optimized and cropped libc library

The libc library is almost the basis of the library and program, but Android did not directly use the libc library, but developed a library: bionic, it implements the vast majority of libc library functions and optimizes them based on the platform. However, a few functions that are rarely used in the system and consume resources are not supported. It only has several hundred kb, saving space and improving execution efficiency. In fact, the 20-80 principle is embodied, and it is necessary to discard unnecessary ones by grasping a few important ones.

7. Make full use of Linux system features

Friends who have analyzed the Linux kernel know that a new process of Linux fork is very efficient and uses the cow mechanism. Android is an independent Virtual Machine for each process (it is said that this design is for security considerations. A process crash at some time will not affect the system and other processes .) Every process in Android is based on virtual machines, and basic libraries must be loaded. In fact, these are shared. Therefore, starting a new program in Android does not actually consume a lot of memory and CPU resources.

At the same time, Android has an empty process running in the background, which is actually running a virtual machine. When an application is to be started, it runs directly on it. qtopia also has this mechanism.

In the Android system boot process: Start a virtual machine-Start System server? Start launcher. Why not start system server directly when I analyzed the code? (Qtopia directly starts the server). In fact, this feature also applies to Linux.

This feature is simple, but it may take a lot of time to explain it clearly.

8. Efficient paint Mechanism

This feature may have little to do with startup, but it is also one of Android's efficient features. Most of the page changes are not actually full-screen content changes, but partial changes. Android only follows the new partial content based on the changed content, which also improves the efficiency. This also reminds us to try not to paint full screen content when reloading the paint method during application development.

This article is transferred fromWww.35java.com

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