admin管理员组

文章数量:1391860

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(
            "

本文标签: flutterReading Health Connect Data Simultaneously Without App Pausing or DelayStack Overflow