1

I'm developing a workout tracking app that integrates with Health Connect to collect and process sensor data during a workout session. The expected workflow is:

The user starts a workout. Health Connect collects sensor data, processes it, and stores it. My app reads the data from Health Connect and displays it to the user. However, there's a noticeable overhead in timing—when my app attempts to read the stored data, it causes interruptions, such as pausing the app or forcing it into the background. Even when running in the background, retrieving and displaying the data to the user takes around 3 to 4 minutes, which is too slow for real-time feedback.

Question: Is there a way to read Health Connect data simultaneously without causing these delays or pausing the app? Ideally, I want to fetch the latest sensor data continuously without waiting for extended processing times.

Attempts so far:

Running the app in the background, but the delay still persists. Trying to fetch data at intervals, but it isn't seamless. Would appreciate any insights or alternative approaches to make this process smoother!

What i hope i can do: (without having to rewrite the whole code)

  • Set an Obeserver to the place health connect writes data to to immediately fill in the stream and decrease latency

  • Read in between data from plugins without actually storing it in
    storage.(If this is what is taking time)

I tried reading the data in live stream but so far i always get values as 0

while (_isTracking && elapsedSeconds < durationInSeconds) {
        DateTime now = DateTime.now();

        // Get data for the last interval only
        List<HealthDataPoint> data = await h.getHealthDataFromTypes(
            startTime:
                now.subtract(Duration(seconds: 10)), // Fetch only last 10 sec
            endTime: now,
            types: healthTypes);

        _liveData.clear(); // Clear old data to avoid accumulation
        _liveData.addAll(data);


\\ data is not getting populaated but if i try after an hour by modifying the function at different time intervals it works

        \\\ other code

        print(
            "🔄 Live Data Update: Steps: $totalSteps, Calories: $totalCalories, Distance: $totalDistance km");

        await Future.delayed(Duration(seconds: 5)); // Update every 5 seconds
        elapsedSeconds += 5;
      } ```
4
  • Is the originating app (i.e. the app that writes the sensor data to Health Connect) your own? If not, you may be running into the fact that the frequency at which other apps write to Health Connect is not guaranteed. Health Connect doesn't collect sensor data, but is a place for apps to read and write the data they collect. Commented Mar 12 at 14:45
  • @Breana The app is my own, i haven't written code to calculate the health data from sensors, i was under the impresssion that google fit, apple fitness calculate it by default and store it into the health connect, i wanted to get access to this data, do you mean to tell me that my app would be faster if i write this code myself and calculate it ? Is there no approach where i can access this data as it is being writtent o health connect? Commented Mar 12 at 18:08
  • Apps like Google Fit, Samsung Health, and Fitbit will calculate/track data and write it into Health Connect, but in most cases it isn't a steady stream that can be read back immediately. For some datatypes, new data may only be written every 15 minutes: developer.android.com/health-and-fitness/guides/health-connect/…. So you definitely can read it back as it's being written, but there might not be new data immediately. Commented Mar 12 at 20:44
  • Thank you @Breana I will take a look at these materials Commented Mar 13 at 13:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.