Skip to content

Commit 771ce51

Browse files
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

3 files changed

+176
-125
lines changed

sdk/@launchdarkly/observability-android/lib/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525

2626
// Android
2727
implementation("androidx.activity:activity:1.11.0")
28+
implementation("androidx.lifecycle:lifecycle-process:2.6.2")
2829

2930
// Coroutines
3031
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")

0 commit comments

Comments
 (0)