Skip to content

fix: keep the host Activity alive when a backgrounded survey closes [ENG-3845] - #99

Merged
pandeymangg merged 2 commits into
mainfrom
anshuman/eng-3845-keep-the-android-host-activity-alive-when
Nov 9, 2026
Merged

pandeymangg merged 2 commits into
mainfrom
anshuman/eng-3845-keep-the-android-host-activity-alive-when

Conversation

@pandeymangg

@pandeymangg pandeymangg commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes ENG-3845

Fixes #94

What & why

Was: A survey that closed itself while the app was in the background finished the host Activity. Coming back from Recents started the app fresh.

Now: Only the survey is dismissed. The SDK never finishes the host Activity, in the foreground or the background.

The survey-library load-error path runs through the same function, so it no longer ends the host either.

Where to look

  • safeDismiss: dismissAllowingStateLoss() replaces both finish() calls.
  • sonarcloud.yml: the job is pinned to ubuntu-24.04. ubuntu-latest became 26.04, where the "Setup KVM" step fails, so SonarCloud could not run at all. Not part of the fix.

Breaking changes

  • This PR contains breaking changes

None. safeDismiss is internal to the SDK.

Migrations & env

  • none

How this was tested

Rerun: ./gradlew :android:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.formbricks.android.webview.FormbricksFragmentDismissInstrumentedTest (needs an emulator)

Coverage

Behaviour How Outcome
Close after the host saved its state keeps the host alive (no overlay, dialog) instrumented (red on main) 2 tests fail on main, pass now
Close while the host is stopped, then resumed: survey gone, host alive, next survey shows instrumented (red on main) Fails on main the same way, passes now
Foreground close still dismisses the survey and leaves no layer instrumented (guard) Passes on main and now
Whole instrumented suite instrumented 174 tests, 0 failures
Finish the survey, press Home a second later, return from Recents manual Same Activity, counter 5. On main: new Activity, counter 0
Screenshots and event log
Before (main) After (this PR)
Host tap counter reset to 0 after returning from Recents Host tap counter still 5 after returning from Recents

Same scripted flow for both: tap the host counter five times, open the survey, finish it, press Home one second later, wait ten seconds, return from Recents. Lifecycle from adb logcat -b events; onClose is from the SDK log.

main:

12:35:48.415  wm_stop_activity     MainActivity          <- Home pressed
12:35:52.061  onClose              the survey closes itself
12:35:52.065  wm_finish_activity   MainActivity, app-request
12:35:52.066  wm_destroy_activity  MainActivity, finish-imm
12:35:59.606  wm_create_activity   MainActivity          <- a new Activity on return

This PR:

12:36:37.464  wm_stop_activity     MainActivity          <- Home pressed
12:36:41.062  onClose              the survey closes itself
12:36:48.750  wm_resume_activity   MainActivity          <- the same Activity, no finish or destroy

Open gaps

  • If Android kills the process and restores the host from saved state, the survey fragment would come back, because the removal is not in the saved state. Not tested.
  • The dialog tests fake the saved state with onSaveInstanceState instead of a real stop. Only the no-overlay path has a real stop and resume test.
  • SonarCloud passes, but it reports no coverable new lines (0 of 178), so it does not measure whether the new tests cover safeDismiss. The red-on-main runs above are the proof.

…ENG-3845]

Once the host has saved its state, dismiss() throws, so safeDismiss()
finished the host Activity instead and the app restarted on return.
Dismiss with state loss and never touch the host.

The survey library load-error path runs through the same function.
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 9a933880-1885-4588-9d7d-7ab7dea0d0a3
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

ubuntu-latest now serves 26.04, where qemu-kvm has no install candidate, so the Setup KVM step fails before any analysis runs. 24.04 is the image the last green runs used.
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@pandeymangg
pandeymangg added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit a75b48c Nov 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the Android host Activity alive when a backgrounded survey auto-closes

2 participants