Intive Blog

Google I/O 2016: Android battery and memory optimization

Chats, games, messages, mails, Facebook, Instagram, Twitter, Happn, Tinder. It has been long now that our cell phones are much more than just phones and, hardly ever would we leave our homes without a battery charger. Precisely, because of all the activities we perform, a charge –many a time – may not be enough for the whole day. But, besides having to charge our devices, what do we actually know about optimization of battery use on Android systems?

Most of the battery dies out when the device is on due to the brightness on its screen. When the screen is off, the CPU (central processing unit) usage is what consumes most of the battery and the radio is also used whenever we send or receive information from the network.

To understand better the way the radio works, here is the following graphic:
2

On the graph we can observe little rays which stand for the amount of energy consumed according to the radio status. When the radio is idle (in stand-by mode), it consumes very little. When the radio starts transmitting, there is a latency of 2 seconds to go to full power. The biggest consumption takes place at this stage. When it stops sending and receiving, it stays 5 seconds in low-consumption mode which enables to have less latency in case it is used again. If it remains idle for 12 seconds, it goes back to stand-by mode.
3

It is important, therefore, to highlight here the three principles of design to improve battery usage. These are the following:

  1. To reduce all background activities our application is performing.
  2. In case the before mentioned is impossible, we should reduce all activity when the device is charging.
  3. If item 2 is not feasible either, perform connections together with other applications to avoid starting the radio.

4

To perform such connection, Marshmallow introduced a feature called Doze. After an idle period after which the screen goes off (5 minutes), Doze disables all background activities, network access, and tasks and alarms are put off. It also disables the GPS and WiFi.

Doze enables task windows where all the activities are performed together and the radio is activated only once.

5

With the Android N release, within the first window of five minutes, the wakelocks, alarms, GPS and WiFi are kept enabled.

6

As from API 21 the class JobScheduler is available, this allows us to perform connections in that time window, depending on the type of network we are connected to (wifi consumes less than the cell phone network), if the device is being charged or if it is being used.

7

8

In case of the API’s previous to 21 and iOS devices, there is an API GCM JobDispatcher, now called Firebase JobDispatcher.

After this introduction, we hope to have shed some light on doubts regarding optimization of its applications and improvements on battery usage on cell phones.

Diego Pappalardo

Diego has been developing Android applications for invite – FDV since February 2015. He is also a team leader for the Android Team, coordinating research development and writing interesting articles for the intive-FDV community. He graduated in 2009 from Universidad Tecnológica Nacional as an electronic engineer. Besides being an Android rock star, Diego has in-depth knowledge about Java, Git, mobile devices and software development in general.

Add comment