Class DataSystemBuilder

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

public class DataSystemBuilder extends Object
Configures the SDK's data system: how and when the SDK acquires feature flag data across different platform states (foreground, background, offline, etc.).

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

The data system is organized around connection modes. Each mode has a data pipeline consisting of initializers (one-shot data loads) and synchronizers (ongoing data updates). The SDK automatically transitions between modes based on platform state (foreground/background, network availability).

Quick start — use defaults:


     LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
         .mobileKey("my-key")
         .dataSystem(Components.dataSystem())
         .build();
 

Custom mode pipelines — background polling once every 6 hours:


     LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
         .mobileKey("my-key")
         .dataSystem(
             Components.dataSystem()
                 .customizeConnectionMode(ConnectionMode.BACKGROUND,
                     DataSystemComponents.customMode()
                         .initializers(DataSystemComponents.pollingInitializer())
                         .synchronizers(
                             DataSystemComponents.pollingSynchronizer()
                                 .pollIntervalMillis(21_600_000))))
         .build();
 

Change the foreground mode to polling:


     Components.dataSystem()
         .foregroundConnectionMode(ConnectionMode.POLLING)
 

Disable automatic mode switching:


     Components.dataSystem()
         .automaticModeSwitching(AutomaticModeSwitchingConfig.disabled())
         .foregroundConnectionMode(ConnectionMode.STREAMING)
 
When automatic mode switching is disabled, the SDK stays in the foreground connection mode and does not react to platform state changes (foreground/background, network availability). This can be useful when you want full control over which mode the SDK uses.

Granular automatic mode switching — disable switching on lifecycle change, keep switching on network availability change:


     Components.dataSystem()
         .automaticModeSwitching(
             DataSystemComponents.automaticModeSwitching()
                 .lifecycle(false)
                 .network(true)
                 .build())
 

Obtain an instance from Components.dataSystem().

See Also:
  • Constructor Details

    • DataSystemBuilder

      public DataSystemBuilder()
  • Method Details

    • foregroundConnectionMode

      public DataSystemBuilder foregroundConnectionMode(@NonNull ConnectionMode mode)
      Sets the connection mode used when the application is in the foreground.

      This determines which entry in the mode table is used when the SDK resolves the foreground platform state. For instance, setting this to ConnectionMode.POLLING means the SDK will use the polling mode pipeline when the app is in the foreground.

      The default is ConnectionMode.STREAMING.

      Parameters:
      mode - the foreground connection mode
      Returns:
      this builder
    • backgroundConnectionMode

      public DataSystemBuilder backgroundConnectionMode(@NonNull ConnectionMode mode)
      Sets the connection mode used when the application is in the background.

      The default is ConnectionMode.BACKGROUND.

      Parameters:
      mode - the background connection mode
      Returns:
      this builder
    • automaticModeSwitching

      public DataSystemBuilder automaticModeSwitching(@NonNull AutomaticModeSwitchingConfig config)
      Configures automatic mode switching based on platform state.

      Automatic mode switching controls whether the SDK reacts to application lifecycle events (foreground/background) and network availability changes by transitioning between connection modes. Lifecycle and network switching can be controlled independently via DataSystemComponents.automaticModeSwitching().

      The default is AutomaticModeSwitchingConfig.enabled(), meaning the SDK reacts to both lifecycle and network events.

      Use AutomaticModeSwitchingConfig.disabled() to disable all automatic switching. When disabled, the SDK stays in the foreground connection mode for its entire lifecycle.

      Example — disable lifecycle switching but keep network switching:

      
           Components.dataSystem()
               .automaticModeSwitching(
                   DataSystemComponents.automaticModeSwitching()
                       .lifecycle(false)
                       .network(true)
                       .build())
       

      Parameters:
      config - the automatic mode switching configuration
      Returns:
      this builder
      See Also:
    • customizeConnectionMode

      public DataSystemBuilder customizeConnectionMode(@NonNull ConnectionMode mode, @NonNull ConnectionModeBuilder builder)
      Overrides the data pipeline for a specific connection mode.

      This only affects the specified mode. All other connection modes that are not customized continue to use their default pipelines. For example, customizing ConnectionMode.BACKGROUND does not change the behavior of ConnectionMode.STREAMING or any other mode.

      Example — set background polling to once every 6 hours:

      
           Components.dataSystem()
               .customizeConnectionMode(ConnectionMode.BACKGROUND,
                   DataSystemComponents.customMode()
                       .initializers(DataSystemComponents.pollingInitializer())
                       .synchronizers(
                           DataSystemComponents.pollingSynchronizer()
                               .pollIntervalMillis(21_600_000)))
       
      Parameters:
      mode - the connection mode to customize
      builder - the pipeline configuration for this mode
      Returns:
      this builder
    • getForegroundConnectionMode

      @NonNull public ConnectionMode getForegroundConnectionMode()
      Returns the configured foreground connection mode.
      Returns:
      the foreground connection mode
    • getBackgroundConnectionMode

      @NonNull public ConnectionMode getBackgroundConnectionMode()
      Returns the configured background connection mode.
      Returns:
      the background connection mode
    • getAutomaticModeSwitchingConfig

      @NonNull public AutomaticModeSwitchingConfig getAutomaticModeSwitchingConfig()
      Returns the automatic mode switching configuration.
      Returns:
      the automatic mode switching config
    • getConnectionModeOverrides

      @NonNull public Map<ConnectionMode,ConnectionModeBuilder> getConnectionModeOverrides()
      Returns any user-specified mode overrides.
      Returns:
      an unmodifiable map of overridden connection modes
    • buildModeTable

      @NonNull public Map<ConnectionMode,ModeDefinition> buildModeTable(boolean disableBackgroundUpdating)
      Builds the full mode table by starting with defaults and applying any user overrides and LDConfig-level settings.

      If disableBackgroundUpdating is true, the background mode entry is replaced with an empty pipeline (no initializers or synchronizers).

      Parameters:
      disableBackgroundUpdating - whether background updates are disabled
      Returns:
      the complete mode table