Android 8.0 Battery Safe
Your Environment
- Plugin version: 2.14.2
- Platform: Android
- OS version: 8.0
- Device manufacturer / model: Moto Z2 Play
- React Native version (
react-native -v): react-native-cli: 2.0.1 react-native: 0.57.8 - Plugin config
const state = await BackgroundGeolocation.ready({
reset: __DEV__,
distanceFilter: 50,
stopOnTerminate: false,
startOnBoot: true,
foregroundService: false,
url: `${API}/geolocations`,
headers: await Request.getHeaders(),
autoSync: true,
debug: false,
notificationTitle: I18n.t("app:notificationTitle"),
notificationText: I18n.t("app:notificationText"),
notificationColor: primaryColor,
notificationSmallIcon: 'mipmap/ic_tracker',
});
if (!state.enabled) {
BackgroundGeolocation.start();
}
Expected Behavior
Use low battery
Actual Behavior
Use lots of battery.
In 1 hour and 13 minutes the application consumes 9% without opening it, while the Netflix that was opened and watch an episode of ~47 minutes consumes only 3%

Over a 1 day period, it consumed 77%, remaining open only 6 minutes

Context
Get monitoring user location without consuming too much battery.
Ideally, the application will not run in the background when the device is stopped and start when the device starts moving.
I know I can for the service configuring stopOnStationary however there is no startOnMoving configuration.
Any idea of setup that can be done?
I know I can for the service configuring
stopOnStationaryhowever there is nostartOnMoving
The plugin automatically toggles location services on/off based upon Motion API. stopOnStationary means "#stop on stationary", not "enter stationary-state on stationary", which it already does.
Are you observing your logs?
Please don't post long logs to the thread, attach them as files.
You should observe your logs over a long period of time to see long the plugin remains in the tracking-state and how often it performs HTTP requests. HTTP requests consume far more energy than GPS. Reduce battery by reducing HTTP requests.
See the HTTP Guide
Hi @christocracy
I changed the HTTP settings to group 10 records, however the application continues consuming battery.
Added Settings:
batchSync: true,
autoSyncThreshold: 10,
logLevel: BackgroundGeolocation.LOG_LEVEL_DEBUG,

Here is the log. My battery reached 100% at 21:26, more precisely in that line
02-26 21: 26: 00.175 DEBUG [BackgroundGeolocationService onActivityRecognitionResult] still (100%)
So the screenshot above is showing the consumption of this line onwards.
Why is your code constantly doing #getCurrentPosition?
I'm not doing #getCurrentPosition. I noticed that by doing #ready sometimes the GPS icon on my smartphone is displayed, so I put it to print the log in a different way.
await BackgroundGeolocation.destroyLog();
console.log(await BackgroundGeolocation.getLog());
const state = await BackgroundGeolocation.ready({
// reset: __DEV__,
//
distanceFilter: 50,
stopOnTerminate: false,
startOnBoot: true,
foregroundService: false,
url: `${API}/geolocations`,
headers: await Request.getHeaders(),
autoSync: true,
batchSync: true,
autoSyncThreshold: 10,
logLevel: BackgroundGeolocation.LOG_LEVEL_DEBUG,
debug: false,
notificationTitle: I18n.t("app:notificationTitle"),
notificationText: I18n.t("app:notificationText"),
notificationColor: primaryColor,
notificationSmallIcon: 'mipmap/ic_tracker',
});
console.log("\n\n\n\n");
console.log(await BackgroundGeolocation.getLog());
console.log(state.enabled);
setTimeout(async () => {
console.log("\n\n\n\n");
console.log(await BackgroundGeolocation.getLog());
}, 10000);
I obtained the following log
PS: I'm doing #ready on index.js
From your log file in here
This is not normal behaviour of the plugin. You are explicitly periodically requesting the current position, burning the battery.
02-26 20:16:47.664 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 20:32:02.905 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 20:46:47.363 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 21:02:10.369 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 21:16:57.019 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 21:34:32.496 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 21:46:52.560 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 22:03:27.049 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 22:20:04.961 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-26 23:26:58.838 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 00:56:28.595 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 01:25:35.484 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 01:41:33.485 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 01:59:14.839 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 02:57:18.387 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 04:48:29.312 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 05:55:55.863 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 06:05:52.890 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 06:21:05.555 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 06:40:26.985 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 06:56:55.078 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 07:10:38.964 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 07:25:58.633 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 07:36:54.438 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
02-27 07:52:14.232 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired current position
Are you sure you don't have a background-fetch task periodically requesting the current position?
I'm using background-fetch just to update Geofences, with #removeGeofence and #addGeofences, but also doing #ready. Assuming #ready does #getCurrentPosition as we can in the logo file see here 02-28 17:54:04.580 23765 24452 I ReactNativeJS: 🔵 Acquired current position, can we assume that this is what is burning the battery?