Class AutomaticModeSwitchingConfig

java.lang.Object
com.launchdarkly.sdk.android.integrations.AutomaticModeSwitchingConfig

public final class AutomaticModeSwitchingConfig extends Object
Granular control over which events trigger automatic connection mode switches.

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:
  • Method Details

    • enabled

      public static AutomaticModeSwitchingConfig enabled()
      Returns a config with both lifecycle and network switching enabled.
      Returns:
      the enabled config
    • disabled

      public static AutomaticModeSwitchingConfig 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 mode when the app goes to the background, and back to the foreground connection mode when 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.OFFLINE when network connectivity is lost, and back to the appropriate mode when connectivity is restored.

      Returns:
      true if network-based mode switching is enabled