GuidesModules

Background sync on the next client (preview)

Schedule health imports and offline measurement delivery with the next client

  • Stable unknown
  • Release candidate since 1.16.1-rc.4
  • Development since 1.16.1-dev.2141+3474979

@ovok/native/next/background-sync exposes Android background task helpers and cross-platform offline measurement scheduling for apps using @ovok/core/next. It reuses the existing background-sync module and keeps its legacy import path available.

Register a headless task with the host application's task manager, restore the authenticated next client and patient, then run the Health Connect import:

import {
  registerAndroidHealthConnectBackgroundTask,
  runAndroidHealthConnectSync,
} from "@ovok/native/next/background-sync";

registerAndroidHealthConnectBackgroundTask(async () => {
  const { client, patientId } = await restoreHealthSyncSession();

  await runAndroidHealthConnectSync({ client, patientId, dataToSync });
});

Register the handler from the app entry point and restore the client and patient inside it. The SDK checks that the restored session still belongs to patientId before importing. See the full background-sync guide for platform setup and the background-sync API reference.

Core offline measurement queue

Install the Expo task packages in the host app:

npx expo install expo-background-task expo-task-manager

Define the task from the app entry point so it is available when the OS starts a fresh JavaScript runtime. Restore the client from the host app's secure session storage inside the callback; the SDK never serializes credentials into task input.

import {
  registerOfflineMeasurementBackgroundTask,
  scheduleOfflineMeasurementBackgroundSync,
  cancelOfflineMeasurementBackgroundSync,
} from "@ovok/native/next/background-sync";

registerOfflineMeasurementBackgroundTask(() => restoreOvokClient());

async function onBackgroundSyncEnabled() {
  await scheduleOfflineMeasurementBackgroundSync({
    minimumIntervalMinutes: 15,
  });
}

async function onBackgroundSyncDisabled() {
  await cancelOfflineMeasurementBackgroundSync();
}

The restored client must use the same durable storage, tenant, and API base; Core scopes the queue to that owner and retains conditional creates and retry state, so a restarted task can safely retry a queued measurement. Call cancelOfflineMeasurementBackgroundSync to stop future runs.

WorkManager will not run more often than the 15-minute minimum. iOS uses BGTaskScheduler and chooses its own execution time, which may be later than the requested interval. Expo shares one background worker across registered tasks, and the last registered task sets the worker's minimum interval. With Expo Continuous Native Generation, prebuild adds iOS background processing configuration; manually managed iOS apps must add Expo BackgroundTask's required UIBackgroundModes and permitted task identifier to Info.plist.

Last updated on

On this page