קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
השימוש במיקום ברקע יכול להשפיע באופן משמעותי על חיי הסוללה. מערכת Android תומכת בהגבלות על איסוף המיקום ברקע, ומעודדת את המפתחים לבצע אופטימיזציה של האפליקציות שלהם כדי לשפר את יעילות הסוללה. האופטימיזציות האלה מועילות לכל המכשירים, ללא קשר לגרסה של Android שבה הם פועלים.
Fused Location Provider ממשק ה-API הזה משלב אותות מ-GPS, מ-Wi-Fi ומרשתות סלולריות, וגם מד תאוצה, ג'ירוסקופ, מגנטומטר וחיישנים אחרים.
Geofencing: ממשק ה-API הזה מבוסס על Fused Location Provider API, והוא מותאם לביצועים יעילים יותר של הסוללה.
הסבר על התרוקנות הסוללה
איסוף המיקומים והתרוקנות הסוללה קשורים זה לזה באופן הבא:
דיוק: מידת הדיוק של נתוני המיקום. ככלל, ככל שהרזולוציה גבוהה יותר, כך הסוללה נטענת מהר יותר.
תדירות: באיזו תדירות המיקום מחושב. ככל שהמיקום מחושב בתדירות גבוהה יותר, כך צריכת הסוללה גבוהה יותר.
זמן אחזור: המהירות שבה נשלחים נתוני המיקום. בדרך כלל, ככל שהזמן האחזור קצר יותר, צריכת הסוללה גבוהה יותר.
דיוק
אפשר לציין את רמת הדיוק של המיקום באמצעות השיטה setPriority(), ולהעביר את אחד מהערכים הבאים כארגומנטים:
PRIORITY_HIGH_ACCURACY מספק את המיקום המדויק ביותר האפשרי, שמחושב באמצעות כמה שיותר מקורות קלט (הוא מפעיל את ה-GPS, את ה-Wi-Fi ואת הרשת הסלולרית, ומשתמש במגוון חיישנים), ויכול לגרום לירידה משמעותית ברמת הטעינה של הסוללה.
PRIORITY_BALANCED_POWER_ACCURACY מספק מיקום מדויק תוך אופטימיזציה של צריכת החשמל. משתמש ב-GPS לעיתים רחוקות מאוד. בדרך כלל נעשה שימוש בשילוב של מידע על רשתות Wi-Fi ועל תאים סלולריים כדי לחשב את המיקום של המכשיר.
PRIORITY_LOW_POWER מסתמך בעיקר על מגדלי תקשורת ומפנה את הגב לנתוני GPS ו-Wi-Fi, כדי לספק דיוק גס (ברמת העיר) עם מינימום שחיקה של הסוללה.
PRIORITY_NO_POWER מקבל מיקומים באופן פסיבי מאפליקציות אחרות שכבר חושב המיקום שלהן.
אפשר להשתמש באפשרויות 'שימוש מאוזן בחשמל' או 'שימוש חסכוני בחשמל' כדי לענות על הצרכים של רוב האפליקציות לגבי מיקום. כדאי להשתמש ברמת דיוק גבוהה רק באפליקציות שפועלות בחזית ומחייבות עדכוני מיקום בזמן אמת (לדוגמה, אפליקציית מפות).
תדירות
יש שתי דרכים לציין את תדירות הצגת המודעות במיקום:
משתמשים ב-method setIntervalMillis() כדי לציין את המרווח לחישוב המיקום של האפליקציה.
כשמשתמשים ב-setIntervalMillis(), צריך להעביר את הערך הגדול ביותר האפשרי. זה נכון במיוחד לגבי איסוף מיקום ברקע, שגורם לרוב לריקון הסוללה. שומרים מרווחים של כמה שניות לתרחישים לדוגמה שבחזית.
המגבלות על מיקום ברקע שהוצגו ב-Android 8.0 (רמת API 26) אוכפות את האסטרטגיות האלה, אבל כדאי לנסות לאכוף אותן גם במכשירים עם Android 7.0 (רמת API 24) ומטה.
איטית
אפשר לציין את זמן האחזור באמצעות השיטה setMaxUpdateDelayMillis(), בדרך כלל על ידי העברת ערך גדול פי כמה מהמרווח שצוין בשיטה setIntervalMillis(). ההגדרה הזו גורמת לעיכוב בהעברת המיקום, ויכול להיות שעדכוני מיקום רבים יועברו ברצף.
שני השינויים האלה עוזרים לצמצם את צריכת הסוללה.
אם לא צריך עדכון מיקום מיידי באפליקציה, כדאי להעביר את הערך הגדול ביותר האפשרי לשיטה setMaxUpdateDelayMillis(), ובכך להחליף את זמן האחזור בנתונים נוספים וביעילות סוללה.
כשמשתמשים במתחמים גיאוגרפיים, אפליקציות צריכות להעביר ערך גדול לשיטה setNotificationResponsiveness() כדי לחסוך באנרגיה. מומלץ להגדיר ערך של חמש דקות או יותר.
מקורות מידע נוספים
מידע נוסף זמין במסמכים הבאים:
המלצות: במדריך הזה מפורטות כמה פעולות מומלצות שתוכלו לבצע כדי לשפר את ההשפעה של האפליקציה על חיי הסוללה.
תרחישים לדוגמה: במדריך הזה מפורטים כמה תרחישים לדוגמה שבהם יכול להיות שתשתמשו בשירותי המיקום, ומוסבר איך למקסם את ההשפעה על חיי הסוללה במקרים האלה.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-26 (שעון UTC)."],[],[],null,["# About background location and battery life\n\nBackground location usage can significantly impact battery life. Android\nsupports limits to background location gathering, prompting developers to\noptimize their applications for better battery efficiency. These optimizations\nare beneficial for all devices, regardless of the Android version they are\nrunning.\n\nWith [Background Location Limits](/about/versions/oreo/background-location-limits):\n\n- Background location gathering is throttled and location is computed, and delivered only a few times an hour.\n- Wi-Fi scans are more conservative, and location updates aren't computed when the device stays connected to the same static access point.\n- Geofencing responsiveness changes from tens of seconds to approximately two minutes. This change improves battery performance---up to 10 times better on some devices.\n\n| **Note:** These features were first introduced with Android 8.0 (API level 26).\n\nRequired knowledge\n------------------\n\nThis document assumes familiarity with the following APIs:\n\n- [Google Location Services.](https://developers.google.com/android/reference/com/google/android/gms/location/package-summary.html) These APIs offer higher accuracy and impose a lighter battery burden than the [framework location APIs](/reference/android/location/package-summary).\n- [Fused Location Provider.](https://developers.google.com/location-context/fused-location-provider/) This API combines signals from GPS, Wi-Fi, and cell networks, as well as accelerometer, gyroscope, magnetometer and other sensors.\n- [Geofencing](https://developers.google.com/location-context/geofencing/), This API is built on top of the Fused Location Provider API, and is optimized for battery performance.\n\nUnderstand battery drain\n------------------------\n\nLocation gathering and battery drain are related as follows:\n\n- **Accuracy:** The precision of the location data. In general, the higher the accuracy, the higher the battery drain.\n- **Frequency:** How often location is computed. The more frequent location is computed, the more battery is used.\n- **Latency:** How quickly location data is delivered. Less latency usually requires more battery.\n\n### Accuracy\n\nYou can specify location accuracy using the [`setPriority()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setpriority-int-priority) method, passing\none of the following values as the argument:\n\n- [`PRIORITY_HIGH_ACCURACY`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_high_accuracy) provides the most accurate location possible, which is computed using as many inputs as necessary (it enables GPS, Wi-Fi, and cell, and uses a variety of [Sensors](/guide/topics/sensors/sensors_overview)), and may cause significant battery drain.\n- [`PRIORITY_BALANCED_POWER_ACCURACY`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_balanced_power_accuracy) provides accurate location while optimizing for power. Very rarely uses GPS. Typically uses a combination of Wi-Fi and cell information to compute device location.\n- [`PRIORITY_LOW_POWER`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_low_power) largely relies on cell towers and avoids GPS and Wi-Fi inputs, providing coarse (city-level) accuracy with minimal battery drain.\n- [`PRIORITY_NO_POWER`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_NO_POWER) receives locations passively from other apps for which location has already been computed.\n\nUse the balanced power or low power options to satisfy the location needs of\nmost apps. Reserve high accuracy for apps that run in the foreground and require\n*real time* location updates (for example, a mapping app).\n\n### Frequency\n\nYou can specify location frequency using two methods:\n\n- Use the [`setIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setintervalmillis-long-intervalmillis) method to specify the interval for computing your app's location.\n- Use the [`setMinUpdateIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setminupdateintervalmillis-long-minupdateintervalmillis) method to specify the interval for receiving other apps' locations.\n\nPass the largest possible value when using `setIntervalMillis()`. This is\nespecially true for background location gathering, which often drains the\nbattery. Reserve intervals of a few seconds for foreground use cases.\n\nThe background location limits introduced in Android 8.0 (API level 26) enforce\nthese strategies, but your app should strive to enforce them on devices running\nAndroid 7.0 (API level 24) and lower.\n\n### Latency\n\nYou can specify latency using the [`setMaxUpdateDelayMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setmaxupdatedelaymillis-long-maxupdatedelaymillis) method,\ntypically passing a value that is several times larger than the interval\nspecified in the [`setIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setintervalmillis-long-intervalmillis) method. This setting delays\nlocation delivery, and multiple location updates may be delivered in batches.\nThese two changes help minimize battery consumption.\n\nIf your app doesn't immediately need a location update, you should pass the\nlargest possible value to the `setMaxUpdateDelayMillis()` method, effectively\ntrading latency for more data and battery efficiency.\n\nWhen using geofences, apps should pass a large value into the\n[`setNotificationResponsiveness()`](https://developers.google.com/android/reference/com/google/android/gms/location/Geofence.Builder.html#setNotificationResponsiveness(int)) method to preserve power. A value of\nfive minutes or larger is recommended.\n\nFurther reading\n---------------\n\nFor more information, see the following documents:\n\n- [Recommendations](/develop/sensors-and-location/location/battery/optimize): This guide lays out some concrete recommended actions you can use to improve your app's impact on battery life.\n- [Use cases](/develop/sensors-and-location/location/battery/scenarios): This guide provides several common use cases where you might use location services and how you could optimise the impact on battery life for those cases."]]