Early bird prices are coming to an end soon... ⏰ Grab your tickets before January 17

This article was published on August 5, 2013

How to stop your mobile app from being a serious battery drain


How to stop your mobile app from being a serious battery drain

Editor’s Note: The following is a guest post by Rajat Harlalka, a Product Manager with over 8 years of experience in the mobile industry primarily in technology, product management and marketing roles.


While smartphones offer tremendous opportunity to app developers, the constrained resources of mobile also pose certain challenges for developers. One of these challenges is power consumption.

If your app is power-hungry, you are bound to get negative reviews from your customers. In some cases, they may end up deleting your app altogether. Hence, traditionally concerned with performance and memory usage optimization, app developers are increasingly looking to address the challenges of optimizing energy consumption.

While there are several techniques to reduce the energy needs of your app, some of which involve in-depth analysis and optimizations, in this article we touch upon some of the simple guidelines that can drastically improve an application’s performance.

Display

The 💜 of EU tech

The latest rumblings from the EU tech scene, a story from our wise ol' founder Boris, and some questionable AI art. It's free, every week, in your inbox. Sign up now!

Display is one of the biggest power hogs. A research paper on Power Management for Mobile Games estimates that on a HTC Magic Android smartphone, with all components running at peak levels, the LCD display consumes 45 to 50 percent of the total system power respectively. Here are two things to keep in mind:

  • Smartphone operating systems are designed to dim the display automatically in absence of any inputs from user. App developers can override this, but do so only when absolutely needed.
  • The second approach is slightly more complicated and requires more effort. In normal cases, the brightness of the image and the display are set to default levels. However, we can hack this to achieve similar perceived brightness by brightening the image or content and dimming the display, or vice versa. This can be applied to video apps and games, which are known to consume a lot power

Network interfaces

After the display, wireless communication components (such as GSM, 3G, WLAN etc.) are the second-biggest energy consumer in mobile devices. A research paper from NUS mentions that wireless data communication represents roughly 40 percent of energy consumption in mobile devices when the display is on, and roughly 70 percent of energy consumption when the device display is switched off. A few simple ways to limit the usage of network interfaces are:

  • If you have a backend server, design the system so to have burst transfer of data rather than periodic ones. Periodic transfers (such as polling, user behavior etc.) are extremely resource inefficient even though they predominantly generate very little traffic. A simple solution could be to adjust the timing of each periodic transfer instance to overlap with user-triggered data transfers. Do not open too many simultaneous TCP connections, instead use few TCP persistent connections or HTTP Pipelining
  • Data caching can also be used to reduce frequent communication with a server. Both local cache and server cache can be used to decrease the amount of data transferred via the network.
  • Location based services also drain batteries, so don’t poll for location if you do not need it. For instance, if your app needs trajectory information instead of a single position, use a smaller subset of obtained positions — one which is minimal in size, while still providing the overall motion information. Consider leveraging the Significant-Change Location Service if at all possible, as this is the most power efficient method of getting long-term location data in your application. Another technique for saving battery life is to turn GPS off when the device is not moving. You can use the device’s accelerometer to verify that motion has started, and then re-engage the GPS
  • Mobile Ads are great examples of how frequent network communication can drain battery power. A recent study indicates that Ads consume 65 percent of an app’s total communication energy, or 23 percent of an app’s total energy.

CPU

When an app is optimized for performance, it is also optimized for power (in most cases). CPU utilization can be decreased by either doing away with unnecessary processing or by optimizing the implementation of necessary processes:

  • In case of games, consider lowering the number of frames-per-second. In many cases, your eyes just cannot tell the difference, unless the frame-rate is skipping. That rate occurs at about 24-30 FPS, and that’s why it’s most used for videos & gaming.
  • Stop your app’s thread when your application terminates, otherwise you will reiterate code when your application isn’t alive
  • It is important for developers to understand the hardware configuration of their target device. For example, when designing audio-video applications, choose the format and codec type that is hardware assisted. Substantial CPU load savings can be realized by developers who utilize hardware accelerated codec’s solutions rather than software based alternatives.
  • Use cloud offloading to partition mobile applications, so that their energy intensive functionality is executed in the cloud.
  • Just like with networking interfaces, avoid polling, accessing the disk frequently and doing computations in small chunks.
  • Consider the use of LookUp Tables for common cases during complex computations.

Avoid unnecessary hardware

Smartphones contain several other components such as a camera, accelerometer, various sensors, etc. When accessing device hardware, you should ensure that your software has failover parameters which turn off the peripheral after period of inactivity. Turning off Bluetooth, GPS and other features when they are not in use is an easy way to save battery life in your app.

Challenges and tools

Many developers aren’t even aware of the amount of energy their app consumes…

Multiple layers of abstractions and middleware that sit between an application and the hardware make it easier for developers to implement mobile application software, but they also take away a lot of control developers have to optimize resource usage.

Sadly, very few tools are available for developers to improve the energy efficiency of their apps. In fact, many developers aren’t even aware of the amount of energy their app consumes.

Good energy management requires a solid understanding of where and how energy is used. There are a few tools and resources available to developers which let them check their app’s power performance. On the iPhone, you can go to Settings > Developer > Energy Diagnostics and turn logging on. You can then use the template in Instruments to analyze the data from this log. It will break it down into several kinds of events and graph it over time, correlate it with CPU and network spikes (pictured below).

Similarly, PowerTutor can be used for Android phones (pictured below). It is noteworthy, however, that software tools have their own limitations — they add to power consumption themselves.

The best way to measure power usage would be at the battery itself, using a digital multimeter in a controlled environment.

More resources

Apple’s Advance App Tricks provide a few excellent tips for developers to minimize the power consumption in their apps. This Intel article is another great resource, as it points out some of the optimizations that developers can do in their source code to lower power consumption.

GSMA has come up with a guide to help developers improve their application’s performance and power consumption. Lastly, Verizon’s App Ranking criteria provides a great benchmark for developers to measure the performance of their apps.

Why should you care?

Sanjay Jha of Motorola has said that poorly written apps eat away a major chunk of your phone’s battery. Battery lifetime is a common cause of frustration in smartphone users and user reviews of applications reveal many customer complaints related to energy usage. Additionally, many app developers have limited experience with energy constrained portable systems and hence mobile apps so far are largely developed in an energy oblivious manner.

The approaches mentioned in this article, albeit simple, can substantially bring down the power usage of your apps. Keep in mind that each of these techniques will have their own trade-offs in performance and memory footprint. Based on your particular needs, choose the methods that work best for you.

Image credit: Thinkstock

 

➤ Read Next: The best USB battery pack for traveling with your mobile devices

Get the TNW newsletter

Get the most important tech news in your inbox each week.