背景行動網路用量過大
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
當應用程式在背景連上行動網路時,會喚醒 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 分析電源使用情況」。調查應用程式行動網路使用行為時,請特別注意「Mobile network use」這一行。
如果想瞭解 Battery Historian 的使用機制,請參閱 Batterystats 和 Battery Historian 的逐步操作說明。
減少行動網路用量
您可以把應用程式的行動網路使用行為移到前景執行,警告使用者註意目前正在進行下載作業,並讓使用者控制是否要暫停或停止下載作業。方法是呼叫 DownloadManager
,然後按照需求設定 setNotificationVisibility(int)
。
為您推薦
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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)"]]