When an app performs Wi-Fi scans in the background, it wakes up the CPU,
causing rate of battery drain. When too many scans occur, the device’s
battery life may be noticeably shortened. An app is considered to be running in
the background if it is in the PROCESS_STATE_BACKGROUND or
PROCESS_STATE_CACHED state.
This document provides tips about diagnosing and addressing excessive Wi-Fi scans in the background.
Investigate the Wi-Fi scans
Tools such as Battery Historian can help you gain more insight into your app's scanning behavior. Battery Historian provides a visualization of Wi-Fi scanning behavior on a per-app basis, which can help you gain a clearer picture of what's happening with your app. For more information about Battery Historian, see Analyzing Power Use with Battery Historian.
For information about the mechanics of using Battery Historian, see Batterystats and Battery Historian Walkthrough.
Reduce the scans
If possible, your app should be performing Wi-Fi scans while the app is running in the foreground. Foreground services automatically present notifications; performing Wi-Fi scans in the foreground thus makes the user aware of the why and when Wi-Fi scans take place on their device.
For information on how to scan while in the foreground,
see the documentation for the
WifiManager class.
If your app cannot avoid performing Wi-Fi scans while the app is running in the background, it may benefit from applying a Lazy First strategy. Lazy First encompasses three techniques that you can use to cut down on Wi-Fi scans: reduce, defer, and coalesce. For information about these techniques, see Optimizing for Battery Life.
Recommended for you
- Note: link text is displayed when JavaScript is off
- Excessive Mobile Network Usage in Background