Network traffic initiated by your app can usually be significantly optimized, since you can plan for what network resources it needs and set a schedule for accessing them. By applying careful scheduling, you can create significant periods of rest for the device radio and, thereby, save power. There are several Android APIs that can help with network access scheduling, and some of these functions can coordinate network access for other apps, further optimizing battery performance.
This lesson teaches you how to reduce battery consumption by applying techniques for optimizing app-initiated network traffic.
Batch and schedule network requests
On a mobile device, the process of turning on the radio, making a connection, and keeping the radio awake uses a large amount of power. For this reason, processing individual requests at random times can consume significant power and reduce battery life. A more efficient approach is to queue a set of network requests and process them together. This allows the system to pay the power cost of turning on the radio just once, and still get all the data requested by an app.
Using a network access scheduler API for queuing and processing your app data requests can significantly increase the power efficiency of your app. Schedulers conserve battery power by grouping requests together for the system to process. They can further improve efficiency by delaying some requests until other requests wake up the mobile radio, or waiting until the device is charging. Schedulers defer and batch network requests system-wide, across all apps on the device, which gives them an optimizing advantage over what any individual app can do.
Allow system to check for connectivity
One of the most serious and unexpected causes of battery drain is when a user travels beyond the reach of any cell tower or access point. In this situation, the user is typically not using their device, but they notice the device getting warm, and then see that the battery is low or has run out.
In this scenario, the problem is that an app is running a background process that keeps waking up the mobile radio at regular intervals to search for a cellular signal, but finds none. Searching for a cell signal is one of the most power-draining operations there is.
The way to avoid causing this kind of problem for a user with your app is to use a battery-efficient method for checking connectivity. For app-initiated network requests, schedule a job with WorkManager, with the constraint that the job runs when the network is available.