admin管理员组

文章数量:1356750

I'm working on an app whose main task is to send location data. I've found that using a callback with FusedLocationProviderClient and a foreground service works perfectly, regardless of the time interval I set. For example, whether it's every 3, 5, 8, or 16 minutes, the device retrieves the location and performs an API call even when the app is in the background and the screen is turned off.

I was wondering how this mechanism remains battery-efficient and avoids waiting for a maintenance window due to Doze mode or other power-saving states when the screen is off.

I’d appreciate any insights, as I also want to perform other tasks outside this callback at user-defined intervals (both short and long). Currently, I’ve managed to achieve this using newWakeLock.acquire(), but it keeps the CPU awake continuously, which isn’t battery-efficient.

本文标签: