Android-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? In particular, the startup time of an application is very short. This article mainly analyzes the following aspects: 1. Optimized reading of resource files. We know that android has a major advantage in UI development: the xml file is used to describe the UI, in this way, you can modify the layout, display style, and font size of the UI without modifying the code. 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. During installation, the Android app that optimizes the dex file is 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. The image application of the Android database is loaded with 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 Machine 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 comes out, it actually only supports armv5te instruction sets, because the android system is specially optimized for armv5te, make full use of the execution pipeline of armv5te to improve the execution efficiency. This is also the reason why the running effect is not very good in 2440 M Samsung, and the running on M omap cpu is relatively smooth, therefore, the latest Code provides Optimization for x86 and armv4. 6. The optimized and cropped libc library Libc library is almost the basis of the library and program. However, android did not directly use the libc library, but developed its own 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. Www.2cto.com 7. Friends who have analyzed the linux kernel by taking full advantage of linux system features know that linux fork is a new process that 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. The efficient paint mechanism 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.

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.