Skip to content
Codeskop

Offline & background sync

Every event is written to the device first and uploaded later, so poor connections, airplane mode and app restarts don't lose data.

How it works

  1. Capture: an event (crash, ANR, failed request…) is written to a small on-device database, off the main thread.
  2. Schedule: Android's WorkManager runs the upload when the device has a network connection.
  3. Upload: events are compressed and sent in batches. They're removed from the device only after Codeskop confirms it received them.

When events are uploaded

  • Periodically: a WorkManager job runs about every 15 minutes while the device is connected. Android decides the exact time, to save battery.
  • When the connection comes back: the SDK requests a quick sync as soon as the device goes from offline to online.
  • When you ask: Codeskop.flush() starts a sync right away.
Kotlin
lifecycleScope.launch {    Codeskop.flush()   // true if a sync ran}

You rarely need flush. It's useful in testing, when you want to see an event in the dashboard immediately.

If an upload fails, WorkManager retries with increasing delays, starting at 30 seconds. Events stay on the device until an upload succeeds, and the SDK never holds a wake lock or keeps a connection open.

Queue size

The queue uses at most maxQueueMb of disk (10 MB by default). When it's full, the oldest low-priority events, such as request timings and heartbeats, are removed first.

Crashes and ANRs are never evicted

However full the queue gets, crashes and ANRs are kept, so a flood of network events can never push out a crash.

One more limit: any single event larger than 64 KB is dropped, because it couldn't be uploaded.

Presence heartbeats

While your app is in the foreground, the SDK adds a small heartbeat event about every 45 seconds. That's how the dashboard knows how many people are using the app right now. Heartbeats travel in the normal sync batches. They don't wake the device or make extra connections, and they stop when the app goes to the background.

Delivery guarantees

  • At least once: an event is removed only after the server accepts it. In rare cases, such as a lost response, an event can be sent twice. Every event has a unique ID, and Codeskop discards duplicates when they arrive.
  • Survives restarts: the queue is on disk, so it outlasts crashes, force-stops and reboots.

Next steps

Events not showing up? See Troubleshooting.