Analysis on Android power-saving Development and android power-saving

Source: Internet
Author: User
Tags notification center

Analysis on Android power-saving Development and android power-saving

Previously, I was writing about Android performance optimization. I believe that all performance optimization for Android App power-saving development can achieve the power-saving Development of apps. Therefore, an Android App that saves power, performance Optimization plays an important role. In addition, according to my daily Android development experience, LZ has sorted out several development skills on power saving for Android apps. I hope you will not give me any suggestions.


1. Performance Optimization for Android power-saving Development


My previous blog has been summing up, just a little, http://blog.csdn.net/wtyvhreal/article/details/44172125


Ii. Android power-saving Development-CPU frequency reduction


As we all know, in the ranking of android system power consumption, cpu power consumption accounts for a large proportion, that is, cpu usage and usage frequency directly or indirectly affect the power allocation and usage. However, the android-sdk does not provide similar cpu management functions for android Developers, however, many power-saving applications or professional cpu management software provide cpu downgrading or overclocking functions.

Http://blog.csdn.net/matrix_xu/article/details/8509319 (here there is a blog written in great detail, for reference)


3. Android power-saving Development service


Service Development is inevitable during Android application development. In android, services run in the background, with the same level as activity. Since the service is a service running in the background, it is invisible and has no interface. Like other components, a Service runs in the main thread, so it cannot be used for time-consuming requests or actions. You can open a thread in the Service to perform time-consuming actions in the thread.

We will analyze the power-saving service development from three aspects

1. Check whether the service is alive and the priority is reduced:

If a service is finished, but it is too late to be switched off or kill, and the user cannot see it, the service will always run in the background, which will inevitably consume power. Therefore, we can reduce the priority of some service processes that are not commonly used. When the system memory is tight, services with low process priority may be killed by the system. In addition, you can use the monitoring system broadcast to determine whether the service status is alive, and then manually kill the service if it dies.

2. Use IntentService instead of Service Development:

A common service is always running after it is started. You must call the stopService () or stopSelf () method to stop the service. In order to easily create an asynchronous class that is automatically worth the service, Android provides an IntentService class. IntentService stops automatically after running to reduce power consumption.

3. The background scheduled task Alarm mechanism:

The Service does not need to be running in the background all the time. At this time, the scheduled task is very important. Android scheduled tasks can be implemented in two ways: Timer and Alarm. Timer has an obvious short board and is not suitable for running scheduled tasks in the background for a long time. To make the battery more durable, each type of mobile phone will have its own sleep policy, and the Android phone will automatically bring the CPU into sleep state without any operation for a long time, this may cause the scheduled tasks in the Timer to fail to run normally. However, the Alarm mechanism does not. It can wake up the CPU to ensure that the CPU works normally every time a scheduled task is executed. Important: After Android 4.4, the trigger time of the Alarm task will become inaccurate, and it may be delayed for a period before the task can be executed. This is not a bug, but a system optimization in terms of power consumption. The system automatically detects the number of existing Alarm tasks, and then puts the tasks that have triggered nearly the same time together for execution. This can greatly reduce the number of times the CPU is awakened, this effectively prolongs the battery time.


Iv. Android power-saving Development Network


In addition to the conventional Asynchronous Network, multithreading technology, and local cache, Android power-saving development also has an important aspect: wifi is more energy-saving than cellular data, including 2G (GPRS) and 3G: a) Try to transmit data in Wi-Fi. Of course this is nonsense, but you can consider pre-loading when Wi-Fi is available, for example, the zip package of the Application Center and offline resources of mobile Q web applications; B) network access should be minimized in non-Wi-Fi scenarios, and the necessity should be considered for every background interaction. Although the Wi-Fi access method accounts for 50% of mobile Internet users, some mobile phones are set to disable Wi-Fi connections by standby mode, and even Wi-Fi signals can only be switched to cellular data;

After reading a blog post, I did not know whether the above data test is correct or not, but it can explain some problems. Screen disconnection: screen disconnection transmission. When downloading high loads, Wi-Fi is the most energy-efficient (70mA), 3G (270mA) and 2G (280mA) are equivalent, about 4 times of WiFi; bright screen: bright screen transmission. When the load is high, WiFi is the most energy-efficient (280mA), 3G (360mA) and 2G (370mA), which is about 1.3 times that of WiFi; therefore, in Android Application power-saving development, we can consider how to obtain the network.


V. Android power-saving Development: Android L5.0 (ART) debut


1. Default ART Running Mode

Is the new ART mode introduced in the latest Android 4.4 system significantly different from the popular Dalvik mode. Therefore, LZ makes the following comparison chart between the ART mode and the Dalvik mode. The comparison shows the differences between the ART mode and the Dalvik mode.

This blog is a good http://www.cnblogs.com/shaweng/p/3811461.html.

In Dalvik, every time an application runs, bytecode needs to be converted to a machine code through the real-time compiler, which slows down the running efficiency of the application. In the ART environment, when the application is installed for the first time, bytecode is pre-compiled into machine code to make it a real local application. This process is called pre-compilation. In this way, application startup and execution will become faster. However, the disadvantage of ART is that the pre-compiled robots occupy a larger storage space and the application installation takes a longer time. However, it is acceptable in Android applications to sacrifice space time in exchange for power-saving speed. After all, performance improvement, faster running speed, smoother experience, and longer battery life are more important.

According to tests, Google's latest Android L system can improve its endurance by 36% compared with the previous version.

Highlights of Android 5.0 http://lib.91.com/comments/141029/21755059.html

2. Use JobScheduler API

In the past, if developers wanted to retrieve server data or complete some processing work through the background, the application must first monitor whether an event is happening and set a wake-up time for themselves, once an application starts running, it needs to check the various environment conditions to determine whether it has the conditions to complete the work, or try again later. This method is not only complex, but also error-prone, it will waste resources constantly. For example, when an application is awakened, it can only go to bed and set a time for the next wake-up attempt if the conditions are not met. This is a repeated process.

This issue will be solved by referencing JobScheduler. As a scheduling application, JobScheduler is responsible for providing an appropriate runtime environment when the application is awakened, therefore, developers do not need to let the program check whether the environment meets the requirements. Developers only need to follow the standard process, and the scheduling program will automatically prepare the runtime environment for the wake-up program. Applications can use this scheduler to wake them up. For example, when a device is connected to a charger, the scheduler will wake up the programs that require the processor to work, or upload and download photos and update content when the device is connected to the Wi-Fi network. The scheduler also supports a time window so that it can wake up a group of applications, which will enable those who do not need to precisely wake up the time, however, a program that needs to run every one or two hours can run at the same time point, so that the processor can sleep for a longer period of time.

JobScheduler has great advantages. It not only helps cell phones save power, but also helps developers reduce code writing because they do not need to listen, change and set alarms. Currently, this JobScheduler class has been added to the Android L Developer Preview version.

3. Various new power-saving modes and technologies

(1) brand new Material Design user interface;

The new user interface is more concise and colorful. The animation effect is more reasonable and vivid. At the same time, a 3D view of real-time shadows is added, and more card-style display effects are used. The overall platform style has become more unified.

(2) a new notification message system;

Allows users to manage notification messages in the notification center. The original Android notification bar is almost uncontrollable, and all application notifications will pop up. To disable it, you can only set it in each application, or use a third-party software for unified management. However, you do not need to use it now. Android 5.0 already comes with the notification management interface.

(3) The multitasking interface has a brand new Google Now card style;

The notification center integrates more card-type styles, allowing you to perform multiple function operations even when the screen is locked. At the same time, you can customize the priority of notifications so that you do not miss any important notifications. You can also set specific notification permissions. only permitted notification messages are pushed. At the same time, it is also operational. For example, a user calls a game and does not display it in full screen. Instead, an operable notification card is displayed. the user can choose to answer or reject the call, without affecting the game to continue.

(4) Project Volta power-saving mode and BatterySaver power-saving mode;

Android 5.0 uses JobSchedulerAPI and automatic screen brightness adjustment and refresh rate to reduce power consumption. In addition, Project Volta is used to quantify the power consumption of each application, when the mobile phone is no longer powered, the CPU clock speed is automatically reduced or the communication module is disabled to get a longer waiting time. A Battery Bistorian Battery history function is provided to display the power consumption of a device in detail.


6. Reference

Http://blog.csdn.net/dyllove98/article/details/43407093

Http://blog.csdn.net/matrix_xu/article/details/8509319

Http://lib.91.com/comments/141029/21755059.html

Http://tech.qq.com/a/20140702/026949.htm

Http://news.mydrivers.com/1/310/310617.htm

Http://mobile.51cto.com/abased-419415.htm

Http://www.pc841.com/shoujizhishi/28594.html

Http://mobile.51cto.com/news-417703.htm



The power saving of Android is a big topic. LZ is not easy to learn. You can share some good ideas with us...






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.