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.
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.
It is important, therefore, to highlight here the three principles of design to improve battery usage. These are the following:
- To reduce all background activities our application is performing.
- In case the before mentioned is impossible, we should reduce all activity when the device is charging.
- If item 2 is not feasible either, perform connections together with other applications to avoid starting the radio.
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.
With the Android N release, within the first window of five minutes, the wakelocks, alarms, GPS and WiFi are kept enabled.
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.
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.