Performance Optimization in Android Development (excerpt: Transcript of Chen Yunxiao's speech)

Source: Internet
Author: User

Hello everyone! I'm Chen Xiaoyun. In fact, I have also done some research on html5. now we are also doing some research. When I used HTML5 to develop some things on G3 a year ago, I found that native does not support HTML and began to develop Android native.CodeDevelopment. Currently, HTML5 will gradually erode native in the next one to two years.ProgramI am talking about the current development, but now Android development is still absolutely dominant. So let's take a look at the optimization of Android R & D today.

How many people know umeng? Thank you! Not many. A brief introduction is a service platform for China Mobile developers. Our core and longest-running feature is a statistics platform that provides sdks to support the entire platform, it serves more than eight thousand of Mobile Manufacturers, including more than fifteen thousand mobile applications. At the same time, we will also issue some reports on a regular basis, which will serve as a reference for developers, application providers, and other partners in the industrial chain.

Various problems arising from different applications are ultimately caused by experience problems. After finding the problem of user experience, let's take a look at the development difficulties and finally propose some optimization strategies. Finally, let's discuss code reuse.

First, let's clarify what we are concerned about. Should you be familiar with this image? This is the architecture of Android. The blue part above is usually the most concerned, basically all Java code, Android is developed based on mid, on which some libraries are provided, these libraries are pure C ++, if you want to call an API, Android provides a virtual layer, which is similar to, but different interfaces, because of this virtual layer, during Android development, there is no need to consider too much memory. This is precisely because many Jav programmers will think that performance optimization is not required when switching to Android. In fact, this is a very wrong idea.

Development on Android is not the same as traditional web development and Java development. Therefore, we need to consider design and optimization related to Android mobile phones during development. Based on the user experience, there are three points: first, the user needs to be fast. Because the mobile phone mainly accesses data, there are several ways to obtain the data. The first is the memory, which is five milliseconds to get one data. I also have a memory file, a database, and a traditional Io. This takes hundreds of milliseconds, and I/O needs to be taken to the table. This is not a long time. If your program is slow, the user will immediately see a system prompt box saying that there is no response, should it be turned off? If the user should unmount it after it is turned off, it is not enough after it is uninstalled, I will give you a few negative comments. I will give you a star. When someone else sees this, they may never download this program again. You may need to find a lot of water troops to brush off one-star comments. This is a bad experience.

The first is fast, and the second is friendly. We must ensure smooth and natural user operations. There is also a problem with Android, which is caused by many Android models. However, Android provides many system-level optimization policies to help us avoid these problems. Do not block users with complicated prompts. Because Android is particularly open, smartphones are now relatively open. As mentioned in the previous article 2.0, there is also a user notification. If this is too abuse, it will also make users dislike it. Do not completely copy the IOS design. Android has many characteristics, such as the single menu key, Return key, and management, which are different from those of IOS.

There is a return key on Android. Many IOS designers bring the IOS menu key and use it directly when they come over, ignoring the android button, breaking user expectations, he will feel at a loss, and all system native programs make full use of the Return key. Therefore, we need to respect user expectations and satisfy their psychological expectations.

The third point related to user experience is power saving. If a mobile phone needs to be charged every day, isn't it a mobile device? I don't think so. First, we need to avoid some complexity.AlgorithmI have a friend who once implemented the analysis table on the Android mobile phone. Is it an email from a large company like Google or a hierarchical one? This email is used for analysis first and then for analysis, he will be proud of it after he finishes. However, the user found that when he opened the application, the system would find that the power consumption was too high. In a few days, he updated the system himself, saving a lot of electricity, and the performance was not greatly affected. Do not involve complicated algorithms on mobile phones.

Because of the multi-process, multi-restricted process, and no exit Design for Android, you can design a program that will always run on the background, provide some information and provide some time. I suggest you consider two different requirements: Real-time and non-real-time. If Google features are recommended in real time. If it is not a real-time requirement, we recommend that you extend the value of time, for example, every few hours or once a day. In addition, the time can be set flexibly. 5. For example, if an update key is set, you can put a field. This field indicates the update cycle. Complete the field each time you update the key. It may take a few minutes to handle the issue. You can update it when you need a platform update. If you don't need it, set the time limit to a little longer.

There are also network requests that should not be too long. On average, each user takes one minute to use. Currently, the last GPS request on the Android mobile phone (basically 2G in China Mobile) is more common at a time than 10 seconds, once the connection is 20 seconds, the user who connects three times is closed. Therefore, do not send requests frequently. Some compression methods can be used to reduce the number of network times.

(I think if you want to do a good job in Android development, you must be able to access foreign forums and learn from each other. Because foreign forums have the most advanced and cutting-edge android technology)

Second, the adaptation problem involves several issues, including hardware, resolution, and OS. Android phones have different prices. One of our partners, camera360, said they needed a lot of Optimization on different cameras when taking photos. Some were 2 million pixels, some were tens of millions of pixels, and they were totally different in image processing. This is a pain point.

Next, let's take a look at the resolution. This is the second quarter's conclusion. No mobile phone resolution occupies the dominant position. The most is 800 × 480, which only accounts for less than 30% of the resolution. The remaining different resolutions are amazing. Now there is a huge amount of Android in China, and it is impossible to ignore a very strange resolution. meizu's 980x640, but accounts for 6% of the resolution, so there is no way to ignore it.

This is a recent image of Android split. According to statistics, seven out of 18 Android devices do not use the latest version of Android, 12 use the latest version is shorter than a week, and 10 are two generations behind the latest version, 15 Android 3.0 are not running.

There is also memory management. Memory Management in Android is very difficult. For each memory is limited to 24 MB, while for old-fashioned mobile phones, this concept seems to be relatively large, but in fact, the application itself will exceed 10 MB, and the memory space is very small. If you do some image applications and take a few photos, you can directly read them as long and wide, generally, a photo is more than 1 MB. Therefore, out of memory problems often occur. How can we solve this problem? The solution is to optimize the view first. We are good at using the tools provided by Android. Google provides an analytical view structure and provides some suggestions. Do not abuse framelayout. No more than 13 layers of nesting, no more than 80 views. Another tool is traceview, which is used to separate the time of a function. This function contains the time of all subfunctions. In fact, Google provides a very rich set of development auxiliary tools, but there are still many that have not been mentioned, such as a program to test the interface immediately.

How can we reduce the nested layers of view and view? The left side is a graph, and the right side is the upper and lower lines of text. There are two ways to write, one is to pack the text, the other is to write two lines of text, set a relationship. There seems to be no big difference, but let's look at the tree. If nested is used, the sub-module structure changes like this. If nested is not used, the relative location relationship changes like this. If there is no problem with this one, but if the module is applied in a large number in the list, the main line will often become very slow, and the slide will become very slow. These are some small details.

Another problem is that android provides a technology in the image to partially enlarge the image. If the image is stretched directly, the corners of the image become blurred because each pixel is stretched evenly. How can I seamlessly stretch from the left to the right? A brief introduction to this principle. This tool defines an image as two regions. The first is the projection on the left and the top. projection to the middle determines your content, the projected Content determines your PNG. The problem with thumbnail enlargement is that it is scaled up evenly. after enlargement, it becomes extremely fierce. Draw two black lines and draw the above and the left to determine the stretched area. The edge is no longer stretched. That's what it means. The above results can be produced.

What's more complicated? How does the small picture on the left become the picture on the right? You can specify different composite regions. Editing Image Compression brings a great advantage. If the processing is good, you can save a lot of APK size, and the download rate will greatly increase when downloading the APK. I made an inaccurate statistics. The download rate is about 50%, and half of the results will fail. The failure is due to the large package. Image compression is an important technology.

In addition, the system will provide some means to help you adapt the resolution. Provides several different folders, ldpi, mdpi, and hdpi, which represent three different types of precision. The system will analyze the precision for positioning. In addition, try to use DP as much as possible, which is related to the current device. Pixel has a problem. They often want to use it directly. PS is different from Android. What is the problem in pixel? In a word, supports wants to ask developers whether your program is suitable for small screens, large screens, and medium screens. If you choose NOT, the system determines that you have not gone through special configuration. What will happen at this time? For example, a device with a resolution of 800x480 can be converted to a resolution of 533x320 due to the use of APIs. He thinks that you want to draw the points 15ph and 15px, because he wants to help you adapt. At this time, the API reads errors, so try not to use Piel or absolute layout.

Memory optimization. One of the major optimizations is image optimization. We all know that the direct read size of Bi images is x Y. We need to compress ourselves and set the compression ratio. There are a lot of problems with the application. Cross-writing, including m, is actually very simple and can write many things.

There is also a need to understand the compiler optimization principles. To some extent, it is a problem of anti-oo. Do not use getter and setter too much, including a series of problems with access speed.

In addition, tie Feng also talked about C ++ development. c ++ can indeed improve performance in some scenarios. This field is game. If you want to use C ++ in general applications, you need to be careful, unless you have a very good C ++ expert, and the code including C cannot be optimized. At that time, there were a lot of things, it is not as fast as writing with addition.

In addition, buffer must be available for download. Our experience is that we have made a lot of exploration in Data Compression because of SDO. Combined with the two technologies, the packet size sent by the network will be about 30% of the original code, this is a method that saves traffic and reduces failure rates. Some minor problems may occur when others look at the code. In fact, I think the bigger advantage is that it reduces the size of the APK and improves the download success rate of the APK.

Finally, let's talk about how to reuse the code after writing a lot of code. The most traditional method is no different from Java, and its advantage is stability, but its disadvantage is that it cannot integrate resource files.

Android provides a new reuse called Android library. The first step is to create a library project, which can be directly used by others without worrying about resources. There is also a problem with its habits. Developers are not very familiar with this mechanism and there will be resource conflicts. Therefore, you should consider this issue based on your development habits and actual project conditions.

Finally, let's talk about the client technology, and finally compete for services. Therefore, it is important to master server development. I personally recommend that you have an easy-to-use idea. In fact, in the end, everyone is fighting for an interconnected service, rather than how beautiful the client is.

In addition, when the client may perform some complicated computing, consider whether your computing needs to be done and whether data needs to be updated frequently, if yes, you need to place this item on the server. The server and the client involve a set of protocols. However, this problem may not exist after the development, but currently, we need to decide what type of bs2 and CS2.

In summary, the first point should be combined with tracrace and monkey for testing, and then code should be written. Finally, code reuse should be completed. master a server development architecture and become a server-side architecture application as soon as possible. Finally, use the mindset to manage applications. Why? When it comes to operations, we must understand that we have a mechanism to understand users. We are very focused on helping developers understand the various usage of applications, including collecting your crash reports, we also provide a two-way feedback system to tell programmers what the most common mistake is. We provide an interface for users to submit feedback through the interface. He thinks that you have any bad suggestions for you. He can see this suggestion on our website and reply to him after seeing the suggestion, the user will see this reply when starting the application for the second time, establishing a two-way channel between the user and the developer. This provides some application Alliance tools for promotion and cross-promotion.

If you are interested, visit our website and weibo. Thank you!

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.