Skip to main content

Enable session replay on Android

Follow this guide to enable Session Replay for Real User Monitoring (RUM) in your Android app.

Session Replay captures a visual sequence of user interactions in your app by recording periodic screenshots. This allows you to analyze what the user saw before, during, and after an issue — helping you quickly pinpoint the source of errors, performance slowdowns, or unexpected behavior. Use Session Replay to recreate the user experience and better understand the context behind each session.

What you need

Install and initialize the Coralogix Android RUM SDK in your app before enabling Session Replay.

Note

Session Replay extends the Android RUM SDK and must be initialized after the base SDK. Attempting to initialize Session Replay without the base SDK results in an initialization error.

Session Replay by default

Session Replay on Android:

  • Evaluates UI one frame per second (FPS) and captures only if the layout changed since the previous screenshot.
  • Masks all text inputs by default (maskAllTexts = true).
  • Optionally masks only specific text values or regex patterns via textsToMask (when maskAllTexts is false).
  • Redacts sensitive input field types (passwords, emails, numbers, etc.) when configured with maskInputFieldsOfTypes.
  • Optionally masks all image views when maskAllImages is enabled.
  • Samples 100% of sessions by default.

You can customize these defaults using the configuration options below.

Configure and initialize

Use the SessionReplayOptions class to configure capture behavior, privacy masking, and sampling.

import android.app.Application
import com.coralogix.android.sdk.session_replay.SessionReplay
import com.coralogix.android.sdk.session_replay.model.SessionReplayOptions
import com.coralogix.android.sdk.internal.infrastructure.display.enums.EditTextType

class MyApp : Application() {
override fun onCreate() {
super.onCreate()

// Step 1: initialize the Android RUM SDK.
CoralogixRum.initialize(this, sdkOptions)

// Step 2: initialize Session Replay.
val sessionReplayOptions = SessionReplayOptions(
captureScale = 0.5f,
captureCompressQuality = 0.8f,
sessionRecordingSampleRate = 80,
autoStartSessionRecording = true,
maskAllTexts = false,
textsToMask = listOf("password", "secret.*"),
maskInputFieldsOfTypes = listOf(
EditTextType.PASSWORD,
EditTextType.EMAIL
),
maskAllImages = true
)
SessionReplay.initialize(this, sessionReplayOptions)
}
}

Options reference

OptionTypeDescriptionDefault
autoStartSessionRecordingBooleanStart recording automatically.true
captureScaleFloatScreenshot resolution scale factor (0–1). Lower values reduce size and memory usage.0.5f
captureCompressQualityFloatImage compression (0–1). Lower values reduce fidelity and file size.1.0f
sessionRecordingSampleRateInt (0–100)Percentage of sessions to capture.100
maskAllTextsBooleanRedact all on-screen text.true
textsToMaskList<String>Redact only specific text values or regex patterns (used when maskAllTexts is false). Patterns use Kotlin/Java regex syntax.emptyList()
maskInputFieldsOfTypesList<EditTextType>Redact specific input field types (for example, password, email, phone).emptyList()
maskAllImagesBooleanMask all ImageView instances on screen.false
sampleFrameRatePerSecondInt (deprecated)Deprecated — do not change. 1 fps is the only supported capture rate. This field will be removed in a future release.1

Image capture triggers

Screenshots are captured during session replay in the following cases:

  • User taps, scrolls, or swipes on the screen.
  • User navigates between activities or fragments.
  • A periodic capture triggers at 1 fps (layout change evaluation).
  • An error or crash occurs.
  • A manual capture is triggered via SessionReplay.captureScreenshot().

Android Session Replay combines periodic sampling with event-based captures (tap, error) so you still see key moments even if they occur between sampling intervals.

Note

Periodic sampling triggers a capture but only processes the frame if a meaningful layout change has taken place, to avoid noise and improve performance.

Start and stop recording

If autoStartSessionRecording is false, control recording manually:

SessionReplay.startSessionRecording()
SessionReplay.stopSessionRecording()

Manually capture screen

Use captureScreenshot to capture a specific moment in the session:

SessionReplay.captureScreenshot()

Shut down Session Replay

Stop the recorder and release its resources. After shutdown, calling startSessionRecording() again has no effect until you re-initialize.

SessionReplay.shutdown()

Privacy and masking

Coralogix provides flexible masking options to help you meet privacy requirements.

  • Text masking: Use maskAllTexts = true to redact all on-screen text, or use textsToMask to selectively mask specific text values or regex patterns when maskAllTexts is false. Patterns use Kotlin/Java regex syntax (for example, (?i)password for case-insensitive matching).
  • Input field masking: Protect sensitive data such as passwords, emails, and phone numbers by specifying their EditTextType in maskInputFieldsOfTypes.
  • Image masking: Use maskAllImages = true to redact all ImageView instances on screen.
  • View masking: Programmatically mark a specific view as sensitive:
mySensitiveView.maskView()

What masking covers

Masking applies to the whole subtree — every child view is masked too, and a child cannot be opted back out. Masking a container is enough to cover everything inside it.

A masked view, and anything inside it:

  • Is covered by a black overlay in session replays.
  • Absorbs tap markers — a tap landing anywhere inside it draws no marker in the recording, so the replay does not reveal which part of the masked area was touched.
  • Reports its inner text as *** in user interaction events.

Everything else on the interaction event is reported as-is — the element’s ID, class, resolved element name, and touch coordinates — and the event is still emitted. The event carries interaction_context.is_masked_element (true/false) so you can enforce a stricter policy in beforeSend.

Enforcing a stricter policy with is_masked_element

Use the beforeSend callback to drop or redact masked interactions before they leave the device.

Drop every masked interaction:

beforeSend = { event ->
if (event.interactionContext?.isMaskedElement == true) null else event
}

Keep the event but blank the coordinates:

beforeSend = { event ->
if (event.interactionContext?.isMaskedElement == true) {
event.copy(
interactionContext = event.interactionContext?.copy(attributes = buildJsonObject {})
)
} else {
event
}
}
Tip

Always verify your masking rules in staging before going live, especially for sensitive inputs like login screens and payment forms.

Last updated on