Commit 771ce51
feat: Pause and resume replay capture on app background/foreground (#329)
## Summary
This change introduces automatic pausing and resuming of session replay
capture based on the application's lifecycle.
`ReplayInstrumentation` now implements `ProcessLifecycleOwner ` to
track when the app enters the background or foreground. Capture is
paused when the app goes to the background and resumed when it returns
to the foreground. This prevents unnecessary data capture when the app
is not in use.
Also, part of the code was refactored (extracted to functions and better
organized), Global coroutine scope was replaced by a local scope,
shutdown method was created and KDocs were updated.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Automatically pauses/resumes session replay on app
background/foreground, replaces GlobalScope with a managed coroutine
scope, adds lifecycle observer/state-driven capture, idempotent install,
shutdown, and lifecycle-process dependency.
>
> - **ReplayInstrumentation**:
> - **Lifecycle integration**: Add `ProcessLifecycleOwner` observer to
start/stop capture on foreground/background; handle initial state; make
`install` idempotent.
> - **Capture loop refactor**: Replace `GlobalScope` with
`CoroutineScope + SupervisorJob`; drive capture via `MutableStateFlow`;
add OOM-safe pause; run collectors in the managed scope; attach/detach
`InteractionSource`.
> - **API/utilities**: Expose `runCapture()`/`pauseCapture()`; add
`shutdown()` to stop capture, remove observer, cancel scope.
> - **Logging/export**: Store `SessionReplayExporter` and use in
`identifySession`; use shared `LDLogger`.
> - **Build**:
> - Add `androidx.lifecycle:lifecycle-process` dependency.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
341cb93. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Andrey Belonogov <[email protected]>1 parent 7fbdc4c commit 771ce51
File tree
3 files changed
+176
-125
lines changed- sdk/@launchdarkly/observability-android/lib
- src/main/kotlin/com/launchdarkly/observability/replay
- capture
3 files changed
+176
-125
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
0 commit comments