NUKOE

How a fitness app saved 70% battery on Android

• 12 min •
Hands holding a smartphone displaying a fitness app, smartwatch, blurred gym in the background.

A smartwatch can last 27 days without recharging, according to the product page for the Amazfit T-Rex 3. But when you launch your favorite fitness app, the battery drains before your eyes. That is the observation made by a small Android development team — let's call it "FitTrack" — before undertaking a deep overhaul of its app. In a few weeks, it managed to reduce energy consumption by 70%. How? By methodically tackling wakelocks, power-hungry sensors, and overly frequent network synchronizations.

This case, although fictional, illustrates a real problem for mobile app developers: poor energy management can ruin the user experience, especially in the wearables ecosystem where every milliamp counts. According to Dcrainmaker's in-depth test of the Garmin Enduro 3, smartwatch manufacturers make a point of honor of optimizing battery life, going so far as to publish comparative charts. Companion apps must meet the same standard of excellence.

This article offers a dive into the technical behind-the-scenes of such an optimization. We will detail the key steps, the frequent mistakes, and a decision framework for prioritizing actions. At the end, you will have a concrete checklist to audit your own Android app, whether it is dedicated to fitness or any other mobile use.

Understanding the consumption of a fitness app: the true cost of sensors

A fitness app stands out from other mobile apps through its intensive use of sensors and GPS. However, these hardware components are among the most energy-hungry in a smartphone. GPS, for example, can consume several hundred milliwatts when active continuously. The accelerometer and gyroscope, although less demanding individually, put pressure on the processor if they are sampled at high frequency without local processing.

The first reflex of a battery-conscious developer is to quantify this consumption. On Android, the framework provides APIs such as `BatteryManager` and tools such as Battery Historian, which make it possible to attribute consumption to specific components. FitTrack's initial diagnosis revealed that 60% of the energy was consumed by GPS left on continuously during training sessions, even when the user was stationary. The remaining 40% was split between network requests (synchronization every 5 minutes) and wakelocks preventing the system from entering sleep.

This diagnosis is essential: you cannot optimize what you do not measure. Too many teams embark on micro-optimizations of Java code without having identified the real consumption hotspots. Yet replacing a `for` loop with a stream will change nothing if GPS is running at full tilt in the background.

Hunting down wakelocks: the first step toward efficiency

A wakelock is a mechanism by which an app asks the system to keep the CPU (or the screen) awake, thus preventing the device from entering deep sleep. It is a legitimate tool for critical tasks, but its abusive use is one of the main causes of battery drain in the background.

In FitTrack's case, the app held a partial wakelock for the entire duration of a workout session, even when the user had locked the screen and put the phone in their pocket. The CPU remained active at 100% to maintain a Bluetooth connection with a heart rate monitor, whereas the Bluetooth chip could handle this task on its own.

The fix consisted of using wakelocks with an explicit timeout (`acquire(timeout)`) and releasing the wakelock as soon as the data was processed. For background operations, the app switched to `WorkManager` with network and battery constraints, allowing the system to batch executions.

Observed result: time spent in deep sleep increased from 15% to 85% of the duration of a typical session, which directly reduced the app's overall consumption by 25% on its own.

Profile before optimizing: the essential tools

Before touching the code, you need to collect objective data. Android Studio offers several built-in tools:

  • Battery Historian: visualizes consumption by component, wakelocks, CPU state transitions, and network events.
  • Systrace / Perfetto: traces system calls and inter-process interactions, useful for detecting unnecessary wakeups.
  • Android Studio Energy Profiler: provides a live estimate of consumption during a test session.

FitTrack used Battery Historian to generate a report on a 30-minute run. The report showed consumption spikes every 5 minutes corresponding exactly to sync requests. By cross-referencing with the network log, the team found that each sync was sending the entire day's activity history instead of only the new data.

This profiling also revealed that the app was waking the CPU 120 times per hour, mainly because of an `AlarmManager` configured with `setRepeating` instead of `setExactAndAllowWhileIdle` with inexact windows. Each wakeup lasted less than a second, but the cumulative effect on the battery was significant, because the CPU exited low-power mode each time.

Reducing network calls: batched synchronization and smart caching

Fitness apps often need to synchronize workout data with a server. If every GPS point or heartbeat is sent immediately, the cellular or Wi-Fi radio stays active continuously, which drains the battery. The solution is to group sends into batches.

Runner checking fitness statistics on smartphone

FitTrack implemented a local cache with Room, then scheduled synchronizations via `WorkManager` with the `NetworkType.CONNECTED` constraint and a minimum periodicity of 15 minutes. Data collected during a workout session is stored locally and sent in a single block once the session is finished or when the phone is charging.

Another optimization consisted of using GZIP compression for JSON payloads, reducing the size of transferred data by 60%. Less data to send means less radio active time.

The result? Network requests went from 12 per hour to 2, and the cellular radio stays inactive for most of the day. This single measure contributed 15% to the total reduction in consumption.

Optimizing sensor usage: the core of the problem

For a fitness app, sensors are essential, but their use can be considerably optimized. Here are the main techniques applied by FitTrack:

  • GPS in power-saving mode: switching from `PRIORITY_HIGH_ACCURACY` mode (which combines GPS, Wi-Fi, and cellular) to `PRIORITY_BALANCED_POWER_ACCURACY` or `PRIORITY_LOW_POWER` depending on the context. For an outdoor run, high accuracy is necessary, but during a static warm-up, low accuracy is enough.
  • Sensor batching: Android allows requesting batches of accelerometer data rather than a continuous stream. The app can thus process 10 seconds of data at once, reducing the number of processor wakeups.
  • Disabling unused sensors: during a strength training session, GPS is not necessary; only the accelerometer and possibly the heart rate monitor are useful. FitTrack introduced workout profiles that enable only the relevant sensors.
  • Using the Sensor Hub: on many smartphones, a dedicated low-power processor can process sensor data without waking the main CPU. By relying on the `SensorManager` APIs with `SENSOR_DELAY_NORMAL` and delegating processing to the hub, the app reduces CPU-related consumption.

These changes reduced sensor-related consumption by 40% during active sessions.

Integration with smartwatches: the role of the Zepp App and ecosystems

A modern fitness application does not live in isolation: it must often communicate with a smartwatch. Manufacturers like Amazfit or Garmin provide their own companion applications, which serve as a bridge between the watch and the smartphone. According to the Amazfit T-Rex 3 product page, the Zepp application enables an "in-depth analysis of health and fitness data" collected by the watch. This means that the bulk of the processing can be delegated to the watch or to the companion application, rather than to the third-party application.

For FitTrack, integration with smartwatches was an opportunity to rethink its own consumption. Instead of asking the smartphone to collect GPS data continuously, the application can receive data already aggregated by the watch via Bluetooth Low Energy (BLE). This approach offloads the smartphone and reduces GPS activation, which is one of the biggest consumers.

Dcrainmaker's test of the Garmin Enduro 3 shows that recent watches offer impressive battery life (up to 36 days in smartwatch mode for the Enduro 3, according to the comparison chart). This creates pressure on mobile applications not to become the weak link in the energy chain. An app that drains the phone in a few hours while the watch lasts several weeks is unacceptable for users.

FitTrack therefore adopted a "distributed computing" strategy: the watch records the raw data, the smartphone only displays and synchronizes it, and the server performs the heavy analysis. This division of labor maintains a smooth experience while preserving the phone's battery.

Common mistakes that ruin battery life

Even with the best intentions, certain common practices sabotage optimization efforts. Here is a non-exhaustive list of the most frequent mistakes, illustrated with concrete examples.

  1. Using `AlarmManager` with `setRepeating` for non-urgent tasks: each repetition wakes the CPU, even if no data has changed. Prefer `WorkManager` with constraints.
  2. Holding a wakelock for the entire duration of a session: the system cannot enter deep sleep, even if the screen is off and the phone is stationary. Use wakelocks with a limited duration and release them as soon as possible.
  3. Synchronizing all data every time: sending the entire training history with each network request is a waste of bandwidth and energy. Send only incremental data.
  4. Sampling sensors at maximum frequency continuously: an accelerometer at 100 Hz continuously generates 6000 samples per minute, most of which are not necessary for activity detection. Use sensor batching and appropriate frequencies.
  5. Enabling GPS as soon as the app opens: GPS consumes a great deal during the satellite acquisition phase. Enable it only when the user actually starts an activity requiring location.
  6. Ignoring the system's power-saving modes: Android offers Doze mode and App Standby. Failing to take them into account can lead to unexpected behavior and increased consumption.
  7. Performing heavy computations on the main thread: if the UI thread is busy, the system may be forced to keep the CPU at a high frequency, increasing consumption. Always move heavy processing to background threads.

These mistakes are not always obvious; they often result from a lack of knowledge of Android's internal mechanisms. A useful parallel: imagine a car engine idling all night to keep the battery warm. That is exactly what a poorly managed wakelock does.

Decision Framework for Prioritizing Optimizations

Not all optimizations are created equal: some require significant effort for minimal gain, while others offer immediate return on investment. Here is a simple framework for prioritizing actions, based on two criteria: the estimated impact on battery life and the complexity of implementation.

| Optimization Technique | Potential Impact | Complexity | Priority |

|--------------------------|------------------|------------|----------|

| Removal of abusive wakelocks | High (25-30%) | Low | High |

| Migration to WorkManager for periodic tasks | High (15-20%) | Low | High |

| GPS optimization (adaptive mode) | High (20-30%) | Medium | High |

| Sensor batching | Medium (10-15%) | Medium | Medium |

| Network data compression | Medium (5-10%) | Low | Medium |

| Offloading processing to the watch | Medium (depending on the app) | High | Medium |

| Micro-optimizations of code (loops, allocations) | Low (<5%) | Variable | Low |

The golden rule: start with high-impact, low-complexity optimizations. In the case of FitTrack, removing wakelocks and adopting WorkManager were completed in one day of development and delivered 40% of the total reduction.

Next, tackling sensors and GPS requires more thought, because data quality for the user must be preserved. A GPS that is too imprecise will make run tracking unusable. Each change must therefore be carefully tested with real users.

Finally, micro-optimizations should only be considered after the major gains have been exhausted. Spending hours optimizing a loop that runs ten times per second makes no sense if the GPS is still running continuously.

Final Checklist Before Release

To validate an optimized version of your application, here is a checklist to go through:

  • [ ] No partial wakelock acquired without an explicit timeout
  • [ ] All periodic tasks use `WorkManager` or `JobScheduler` with constraints
  • [ ] Sensors are disabled when they are no longer needed (via `unregisterListener`)
  • [ ] GPS is used in adaptive mode depending on context
  • [ ] Sensor data is processed in batches to minimize CPU wakeups
  • [ ] Network synchronizations are grouped and do not exceed a reasonable frequency
  • [ ] Payloads are compressed
  • [ ] The application respects Doze mode and does not bypass battery restrictions without valid justification
  • [ ] A Battery Historian report shows a deep sleep proportion greater than 70% during periods of inactivity
  • [ ] Tests on real devices (not just on emulator) confirm a measurable reduction in consumption

This checklist is not exhaustive, but it covers the critical points that enabled FitTrack to achieve its 70% reduction.

Making Battery a Product Priority

FitTrack's 70% reduction in consumption is not the result of an isolated feat, but of a systematic approach: measure, identify the main contributors, fix gross errors, then refine. This approach can be applied to any Android application, not just in the fitness domain.

At a time when connected watches display battery lives of several weeks, as evidenced by the Amazfit T-Rex 3 with its 27 days and the Garmin Enduro 3 with its comparative charts, mobile applications must rise to the same level of expectation. Users will no longer tolerate an app ruining their phone's battery in a few hours.

The next step for FitTrack is to make greater use of Machine Learning embedded on watches to further reduce dependence on the smartphone. But that is another story. For now, the team is savoring a measurable victory: an application that supports the user without letting them down in the middle of a marathon.

Further Reading

Related articles