Skip to content

chore(test-app): start a second environment when a second key is set - #428

Open
abelonogov-ld wants to merge 1 commit into
andrey/test-app-event-storagefrom
andrey/test-app-two-environments
Open

abelonogov-ld wants to merge 1 commit into
andrey/test-app-event-storagefrom
andrey/test-app-two-environments

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #427.

What

When local.properties sets launchdarkly.secondaryMobileKey, the client is started with that key as a secondary environment through LDConfig.Builder.secondaryMobileKeys. An Env spinner next to Persistence chooses which environment's client the buttons use, through LDClient.getForMobileKey. Without the key the spinner stays hidden and nothing changes.

The selected environment is used by:

  • Evaluate Flag and its flag listener;
  • Track;
  • Eval+Kill 5s, Eval+Kill now, Eval+Crash now, Over-Refresh Eval and Fill 3 Batches;
  • Post 20 MB (which key it posts with);
  • the connection status;
  • the event storage view, which shows that environment's own directory.

These reach both environments whichever is selected, because the SDK applies flush, setOffline, setOnline, identify and close to every environment it started: Flush, Offline, Identify, and the restart a persistence change makes. The status line says so.

The buttons now get their client through doSafeClientAction(client -> ...) instead of reading ldClient after a null check. Status and flag listeners are registered on every environment and show the selected one's connection. The choice is saved in shared preferences like the persistence choice.

Testing

On the API 23 emulator with both keys set:

  • The Env spinner appears.
  • Selecting Secondary switches the connection status to that environment's own information.
  • Track wrote a pending log into the secondary environment's directory only, and the storage view showed it.
  • Flush delivered it.
  • Switching back to Primary showed the primary environment's status and directory again.

Note

Overview
The internal test app can start two LaunchDarkly environments from one LDConfig when launchdarkly.secondaryMobileKey is set in local.properties (wired through BuildConfig.SECONDARY_MOBILE_KEY and secondaryMobileKeys).

An Env spinner appears beside Persistence (hidden without a distinct second key). The choice is persisted so post-kill relaunches match the environment used when the button was pressed. Evaluations, track, kill/crash/over-refresh/fill-batches, Post 20 MB, connection status, and on-disk event storage all follow the selected environment via LDClient.getForMobileKey. Flush, Offline, Identify, and client restarts still fan out to every started environment, matching SDK behavior.

Button and listener paths were refactored so doSafeClientAction / doSafeClientGet take the active client instead of always using the primary ldClient. README documents the new property and UI behavior.

Reviewed by Cursor Bugbot for commit 186c9f1. Bugbot is set up for automated code reviews on this repo. Configure here.

launchdarkly.secondaryMobileKey in local.properties adds a secondary mobile key to the client's
LDConfig. An Env spinner then chooses which environment's client the buttons, the connection status,
Post 20 MB and the event storage view use. Flush, Offline, Identify and the persistence restart
still reach both, as the SDK applies them to every environment.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner November 11, 2026 01:46

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 186c9f1. Configure here.

setupStorageInspector();
storageInspector.startWatching();
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag listeners ignore environment switches

Low Severity

Switching the Env spinner refreshes connection status, the storage view, and the status line, but String Evaluate Flag listeners stay on the environment where they were registered. A later change on that other environment still overwrites the result view, so it can show the unselected environment's value.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 186c9f1. Configure here.

This branch has not been deployed

No deployments
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.

1 participant