Class AutomaticModeSwitchingConfig
By default, the SDK automatically transitions between connection modes in response to both lifecycle events (foreground/background) and network availability changes. This class allows enabling or disabling each independently.
Use DataSystemComponents.automaticModeSwitching()
for granular control, or the convenience factories enabled() and disabled(),
and pass the result to DataSystemBuilder.automaticModeSwitching(AutomaticModeSwitchingConfig)
on Components.dataSystem().
This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode
Examples:
Disable all automatic mode switching (SDK stays in the connection mode it starts in):
LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
.mobileKey("my-key")
.dataSystem(
Components.dataSystem()
.automaticModeSwitching(AutomaticModeSwitchingConfig.disabled()))
.build();
Granular: disable lifecycle switching, keep network switching:
LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
.mobileKey("my-key")
.dataSystem(
Components.dataSystem()
.automaticModeSwitching(
DataSystemComponents.automaticModeSwitching()
.lifecycle(false)
.network(true)
.build()))
.build();
- See Also:
-
Components.dataSystem()DataSystemComponents.automaticModeSwitching()DataSystemBuilder.automaticModeSwitching(AutomaticModeSwitchingConfig)LDConfig.Builder.dataSystem(DataSystemBuilder)
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic AutomaticModeSwitchingConfigdisabled()Returns a config with both lifecycle and network switching disabled.static AutomaticModeSwitchingConfigenabled()Returns a config with both lifecycle and network switching enabled.booleanWhether the SDK automatically switches connection modes in response to application lifecycle events (foreground/background transitions).booleanWhether the SDK automatically switches connection modes in response to network availability changes.
-
Method Details
-
enabled
Returns a config with both lifecycle and network switching enabled.- Returns:
- the enabled config
-
disabled
Returns a config with both lifecycle and network switching disabled.- Returns:
- the disabled config
-
isLifecycle
public boolean isLifecycle()Whether the SDK automatically switches connection modes in response to application lifecycle events (foreground/background transitions).When true, the SDK transitions to the
background connection modewhen the app goes to the background, and back to theforeground connection modewhen the app returns to the foreground.- Returns:
- true if lifecycle-based mode switching is enabled
-
isNetwork
public boolean isNetwork()Whether the SDK automatically switches connection modes in response to network availability changes.When true, the SDK transitions to
ConnectionMode.OFFLINEwhen network connectivity is lost, and back to the appropriate mode when connectivity is restored.- Returns:
- true if network-based mode switching is enabled
-