Class LDConfig.Builder

java.lang.Object
com.launchdarkly.sdk.android.LDConfig.Builder
Enclosing class:
LDConfig

public static class LDConfig.Builder extends Object
A builder that helps construct LDConfig objects. Builder calls can be chained, enabling the following pattern:
 LDConfig config = new LDConfig.Builder()
          .mobileKey("mobile-key")
          .evaluationReasons(true)
          .build();
 
  • Constructor Details

    • Builder

      public Builder(LDConfig.Builder.AutoEnvAttributes autoEnvAttributes)
      LDConfig.Builder constructor. Configurable values are all set to their default values. The client app can modify these values as desired.
      Parameters:
      autoEnvAttributes - - Enable / disable Auto Environment Attributes functionality. When enabled, the SDK will automatically provide data about the mobile environment where the application is running. This data makes it simpler to target your mobile customers based on application name or version, or on device characteristics including manufacturer, model, operating system, locale, and so on. We recommend enabling this when you configure the SDK. See TKTK for more documentation.
  • Method Details

    • mobileKey

      public LDConfig.Builder mobileKey(String mobileKey)
      Sets the key for authenticating with LaunchDarkly. This is required unless you're using the client in offline mode.
      Parameters:
      mobileKey - Get this from the LaunchDarkly web app under Team Settings.
      Returns:
      the builder
    • secondaryMobileKeys

      public LDConfig.Builder secondaryMobileKeys(Map<String,String> secondaryMobileKeys)
      Sets the secondary keys for authenticating to additional LaunchDarkly environments.
      Parameters:
      secondaryMobileKeys - A map of identifying names to unique mobile keys to access secondary environments
      Returns:
      the builder
    • serviceEndpoints

      public LDConfig.Builder serviceEndpoints(ServiceEndpointsBuilder serviceEndpointsBuilder)
      Sets the base service URIs used by SDK components.

      This object is a configuration builder obtained from Components.serviceEndpoints(), which has methods for setting each external endpoint to a custom URI.

      
           LDConfig config = new LDConfig.Builder().mobileKey("key")
               .serviceEndpoints(
                   Components.serviceEndpoints().relayProxy("http://my-relay-proxy-host")
               );
       
      Parameters:
      serviceEndpointsBuilder - a configuration builder object returned by Components.serviceEndpoints()
      Returns:
      the builder
      Since:
      4.0.0
    • applicationInfo

      public LDConfig.Builder applicationInfo(ApplicationInfoBuilder applicationInfoBuilder)
      Sets the SDK's application metadata, which may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.

      This object is normally a configuration builder obtained from Components.applicationInfo(), which has methods for setting individual metadata properties.

      Parameters:
      applicationInfoBuilder - a configuration builder object returned by Components.applicationInfo()
      Returns:
      the builder
      Since:
      4.1.0
    • dataSource

      public LDConfig.Builder dataSource(ComponentConfigurer<DataSource> dataSourceConfigurer)
      Sets the configuration of the component that receives feature flag data from LaunchDarkly.

      The default is Components.streamingDataSource(); you may instead use Components.pollingDataSource(), or a test fixture such as TestData. See Components.streamingDataSource() and Components.pollingDataSource() for details on how to configure them with options that are specific to streaming or polling mode.

      Setting offline(boolean) to true will supersede this setting and completely disable all data sources.

      
           // Setting custom options when using streaming mode
           LDConfig config = new LDConfig.Builder()
               .dataSource(
                   Components.streamingDataSource()
                       .initialReconnectDelayMillis(100)
               )
               .build();
      
           // Using polling mode instead of streaming, and setting custom options for polling
           LDConfig config = new LDConfig.Builder()
               .dataSource(
                   Components.pollingDataSource()
                       .pollingIntervalMillis(60_000)
               )
               .build();
       
      Parameters:
      dataSourceConfigurer - the data source configuration builder
      Returns:
      the main configuration builder
      Since:
      3.3.0
      See Also:
    • events

      public LDConfig.Builder events(ComponentConfigurer<EventProcessor> eventsConfigurer)
      Sets the implementation of EventProcessor to be used for processing analytics events.

      The default is Components.sendEvents() with no custom options. You may instead call Components.sendEvents() and then set custom options for event processing; or, disable events with Components.noEvents(); or, choose to use a custom implementation (for instance, a test fixture).

      Setting offline(boolean) to true will supersede this setting and completely disable network requests.

      
           // Setting custom event processing options
           LDConfig config = new LDConfig.Builder()
               .events(Components.sendEvents().capacity(100))
               .build();
      
           // Disabling events
           LDConfig config = new LDConfig.Builder()
               .events(Components.noEvents())
               .build();
       
      Parameters:
      eventsConfigurer - the events configuration builder
      Returns:
      the main configuration builder
      Since:
      3.3.0
      See Also:
    • http

      Sets the SDK's networking configuration, using a configuration builder. This builder is obtained from Components.httpConfiguration(), and has methods for setting individual HTTP-related properties.
      
           LDConfig config = new LDConfig.Builder()
               .http(Components.httpConfiguration().connectTimeoutMillis(5000))
               .build();
       
      Parameters:
      httpConfigurer - the HTTP configuration builder
      Returns:
      the main configuration builder
      Since:
      3.3.0
      See Also:
    • disableBackgroundUpdating

      public LDConfig.Builder disableBackgroundUpdating(boolean disableBackgroundUpdating)
      Sets whether feature flag updates should be disabled when your app is in the background.

      The default value is false (flag updates will be done in the background).

      Parameters:
      disableBackgroundUpdating - true if the client should skip updating flags when in the background
      Returns:
      the builder
    • offline

      public LDConfig.Builder offline(boolean offline)
      Disables all network calls from the LaunchDarkly client.

      This can also be specified after the client has been created, using LDClientInterface.setOffline().

      The default value is true (the client will make network calls).

      Parameters:
      offline - true if the client should run in offline mode
      Returns:
      the builder
    • evaluationReasons

      public LDConfig.Builder evaluationReasons(boolean evaluationReasons)
      If enabled, LaunchDarkly will provide additional information about how flag values were calculated. The additional information will then be available through the client's "detail" methods (LDClientInterface.boolVariationDetail(String, boolean), etc.). Since this increases the size of network requests, the default is false (detail information will not be sent).
      Parameters:
      evaluationReasons - true if detail/reason information should be made available
      Returns:
      the builder
    • diagnosticOptOut

      public LDConfig.Builder diagnosticOptOut(boolean diagnosticOptOut)
      Set to true to opt out of sending diagnostics data. Unless the diagnosticOptOut field is set to true, the client will send some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK improvements. These diagnostics consist of an initial payload containing some details of SDK in use, the SDK's configuration, and the platform the SDK is being run on; as well as payloads sent periodically with information on irregular occurrences such as dropped events.
      Parameters:
      diagnosticOptOut - true if you want to opt out of sending any diagnostics data.
      Returns:
      the builder
    • maxCachedContexts

      public LDConfig.Builder maxCachedContexts(int maxCachedContexts)
      Sets the maximum number of evaluation contexts to cache the flag values for locally in the device's SharedPreferences.

      Note that the active evaluation context is not considered part of this limit, as it will always be served from the backing SharedPreferences.

      If not specified, the default is LDConfig.DEFAULT_MAX_CACHED_CONTEXTS (5).

      Parameters:
      maxCachedContexts - The maximum number of evaluation contexts to cache; negative values represent allowing an unlimited number of cached contexts
      Returns:
      the builder
    • generateAnonymousKeys

      public LDConfig.Builder generateAnonymousKeys(boolean generateAnonymousKeys)
      Set to true to make the SDK provide unique keys for anonymous contexts.

      If enabled, this option changes the SDK's behavior whenever the LDContext (as given to methods like LDClient.init(android.app.Application, LDConfig, LDContext, int) or LDClient.identify(LDContext)) has an LDContext.isAnonymous() property of true, as follows:

      • The first time this happens in the application, the SDK will generate a pseudo-random GUID and overwrite the context's key with this string.
      • The SDK will then cache this key so that the same key will be reused next time.
      • This uses the same persistent storage (shared preferences) mechanism as the caching of flag values, so that the key can persist across restarts.

      If you use multiple ContextKinds, this behavior is per-kind: that is, a separate randomized key is generated and cached for each context kind.

      Every LDContext must always have a key, even if the key will later be overwritten by the SDK, so if you use this functionality you must still provide a placeholder key. This ensures that if the SDK configuration is changed so generateAnonymousKeys is no longer enabled, the SDK will still be able to use the context for evaluations.

      Parameters:
      generateAnonymousKeys - true to enable automatic anonymous key generation
      Returns:
      the same builder
      Since:
      4.0.0
    • logAdapter

      public LDConfig.Builder logAdapter(LDLogAdapter logAdapter)
      Specifies the implementation of logging to use.

      The com.launchdarkly.logging API defines the LDLogAdapter interface to specify where log output should be sent. By default, it is set to LDTimberLogging.adapter(), meaning that output will be sent to the Timber framework and controlled by whatever Timber configuration the application has created. You may change this to LDAndroidLogging.adapter() to bypass Timber and use Android native logging directly; or, use the Logs factory methods, or a custom implementation, to handle log output differently.

      Specifying logAdapter(Logs.none()) completely disables log output.

      For more about logging adapters, see the SDK reference guide and the API documentation for com.launchdarkly.logging.

      Parameters:
      logAdapter - an LDLogAdapter for the desired logging implementation
      Returns:
      the builder
      Since:
      3.2.0
      See Also:
    • logLevel

      public LDConfig.Builder logLevel(LDLogLevel logLevel)
      Specifies the lowest level of logging to enable.

      This is only applicable when using an implementation of logging that does not have its own external filter/configuration mechanism, such as LDAndroidLogging. It adds a log level filter so that log messages at lower levels are suppressed. The default is LDLogLevel.INFO, meaning that INFO, WARN, and ERROR levels are enabled, but DEBUG is disabled. To enable DEBUG level as well:

      
           LDConfig config = new LDConfig.Builder()
               .logAdapter(LDAndroidLogging.adapter())
               .level(LDLogLevel.DEBUG)
               .build();
       

      Or, to raise the logging threshold so that only WARN and ERROR levels are enabled, and DEBUG and INFO are disabled:

      
           LDConfig config = new LDConfig.Builder()
               .logAdapter(LDAndroidLogging.adapter())
               .level(LDLogLevel.WARN)
               .build();
       

      When using LDTimberLogging, Timber has its own mechanism for determining whether to enable debug-level logging, so this method has no effect.

      Parameters:
      logLevel - the lowest level of logging to enable
      Returns:
      the builder
      Since:
      3.2.0
      See Also:
    • loggerName

      public LDConfig.Builder loggerName(String loggerName)
      Specifies a custom logger name/tag for the SDK.

      When using Timber or native Android logging, this becomes the tag for all SDK log output. If you have specified a different logging implementation with logAdapter(LDLogAdapter), the meaning of the logger name depends on the logging framework.

      If not specified, the default is "LaunchDarklySdk".

      Parameters:
      loggerName - the logger name or tag
      Returns:
      the builder
      Since:
      3.2.0
      See Also:
    • build

      public LDConfig build()
      Returns the configured LDConfig object.
      Returns:
      the configuration