Skip to content

Most visited

Recently visited

navigation

Excessive Wi-Fi Scanning in the Background

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 explains how to detect when your app is performing too many Wi-Fi scans in the background, and provides tips about diagnosing and addressing the problem.

Detect the problem

You may not always know that your app is exhibiting an inordinate number of Wi-Fi scans. If you have already published your app, Android vitals can make you aware of the problem so that you can fix it.

Android vitals

Android vitals can help improve your app's performance by alerting you, via the Play Console, when your app is performing excessive Wi-Fi scanning n the background. Android vitals considers Wi-Fi scanning excessive when an app performs more than 4 scans per hour in 0.10% of battery sessions while running in the background.

A battery session refers to the interval between two full battery charges. For information on how Google Play collects Android vitals data, see the Play Console documentation.

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.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)