后台移动网络使用量过高
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
当应用在后台连接移动网络时,应用会唤醒 CPU 并开启无线装置,而且反复执行此操作可能会耗尽设备的电量。应用如果处于 PROCESS_STATE_BACKGROUND
或 PROCESS_STATE_CACHED
状态,则视为在后台运行。
针对应用在后台运行时过度使用移动网络的情况,本页介绍了如何确定其背后的原因及应对措施。
检测问题
您有时可能并不知道应用在后台运行时过度使用了网络。如果您已经发布了应用,可以通过 Android Vitals 来了解问题并予以解决。
Android Vitals
当您的应用在后台过度使用移动网络时,Android Vitals 可通过 Play 管理中心提醒您,从而帮助您改进应用性能。
一旦应用在后台运行时每天发送和接收的数据共达 50 MB,Android Vitals 即认为其后台网络使用量过高。在 Play 管理中心内,您可以查看出现此行为的电池工作时段所占的百分比。
电池工作时段的定义取决于平台版本。
- 在 Android 10 中,电池工作时段是在给定的 24 小时内接收到的所有电池报告的汇总。电池报告是指两次电池充电(从低于 20% 充到 80% 以上或者从任意电量值充满到 100%)间隔的时间。
- 在 Android 11 中,电池工作时段是固定的 24 小时时间段。
如需了解 Google Play 如何收集 Android Vitals 数据,请参阅 Play 管理中心文档。
调查移动网络使用行为
Battery Historian 等工具可帮助您深入了解应用的移动网络使用情况。Battery Historian 针对每个应用直观呈现移动无线装置的使用情况,可帮助您更清晰地了解应用的动态。如需详细了解 Battery Historian,请参阅使用 Battery Historian 分析耗电情况。在调查应用的移动网络使用行为时,请重点关注“移动网络使用”行。
如需了解 Battery Historian 的使用机制,请参阅 Batterystats 和 Battery Historian 演示。
减少移动网络使用量
您可以将应用的移动网络使用量移至前台,提醒用户目前正在进行下载,并为他们提供暂停或停止下载的控件。为此,请调用 DownloadManager
并根据情况设置 setNotificationVisibility(int)
。
为您推荐
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Excessive Mobile Network Usage in Background\n\nWhen an app connects to the mobile network in the background,\nthe app wakes up the CPU and turns on the radio. Doing so\nrepeatedly can run down a device's battery. An app is considered to be running\nin the background if it is in the `PROCESS_STATE_BACKGROUND` or\n`PROCESS_STATE_CACHED` state.\n\nThis page explains how to determine why your app is excessively using the\nmobile network while running in the background, and what to do about it.\n\nDetect the problem\n------------------\n\nYou may not always know that your app is making inordinate use of the\nnetwork while running in the background. If you have already published\nyour app, Android vitals can make you aware of the problem so that you can fix\nit.\n\n### Android vitals\n\nAndroid vitals can help improve your app's performance by alerting you via the\n[Play Console](https://play.google.com/console/) when your app is\nusing the mobile network excessively in the background.\n\nAndroid vitals considers background network usage excessive when an app is\nsending and receiving a combined total of 50 MB per day while running in the\nbackground. In Play Console you can check percentage of *battery sessions*\nthat exhibit this behavior.\n\nThe definition of *battery session* depends on the platform version.\n\n- In Android 10, a battery session is the aggregation of all battery reports received within a given 24-hour period. A *battery report* refers to the interval between two battery charges either from below 20% to above 80% or from any charge level to 100%.\n- In Android 11, a battery session is a fixed 24-hour period.\n\nFor information on how Google Play collects Android vitals data, see the [Play\nConsole](https://support.google.com/googleplay/android-developer/answer/7385505)\ndocumentation.\n\nInvestigate mobile-network-usage behavior\n-----------------------------------------\n\n| **Warning:** Battery Historian is no longer actively maintained; if possible, consider using [system tracing](/topic/performance/tracing), the [Macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview) power metric, or the [Power Profiler](/studio/profile/power-profiler) to get insights into battery performance.\n\nTools such as Battery Historian can help you gain more insight into your\napp's mobile-network usage. Battery Historian provides a visualization of\nmobile-radio use on a per-app basis, which can help you gain a clearer\npicture of what's happening with your app. For more information about Battery\nHistorian, see\n[Analyzing Power Use with Battery Historian](/topic/performance/power/battery-historian#asd).\nIn investigating your app's mobile-network-usage behavior, you should take\nparticular note of the *Mobile network use* line.\n\nFor information about the mechanics of using Battery Historian, see\n[Batterystats and Battery Historian Walkthrough](/topic/performance/power/setup-battery-historian).\n\nReduce mobile network usage\n---------------------------\n\nYou can move your app's mobile-network usage to the foreground, alerting\nthe user to the fact that a download is in progress, and providing them\nwith controls to pause or stop the download. To do so, call\n[`DownloadManager`](/reference/android/app/DownloadManager), and set\n[`setNotificationVisibility(int)`](/reference/android/app/DownloadManager.Request#setNotificationVisibility(int))\nas appropriate.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Excessive Wi-Fi Scanning in the Background](/topic/performance/vitals/bg-wifi)"]]