FeatureState

Represents the state of a remote feature flag.

This enum is used to manage the current state of Feature.RemoteFeature instances, allowing local overrides of remotely-configured feature flags. This is particularly useful during development and testing when you need to force a feature on or off regardless of what the remote configuration says.

State Transitions

Features typically start in REMOTE state and can be changed to:

  • LOCAL_ON: For testing when feature should be enabled

  • LOCAL_OFF: For testing when feature should be disabled

  • Back to REMOTE: To restore remote configuration control

Persistence

When persisting the state to DataStore, use the ordinal property to store it as an integer, and fromOrdinal to restore it:

// Saving
preferences[key] = featureState.ordinal

// Restoring
val restoredState = FeatureState.fromOrdinal(preferences[key] ?: 0)

Usage Example

// Creating a feature with remote state
val feature = Feature.RemoteFeature(
name = "new_feature",
description = "Experimental new feature",
defaultRemoteValue = remoteConfig.getBoolean("new_feature"),
state = FeatureState.REMOTE
)

// Override locally for testing
featureHandler.setFeatureState("new_feature", FeatureState.LOCAL_ON)

// Restore remote control
featureHandler.setFeatureState("new_feature", FeatureState.REMOTE)

See also

Entries

Link copied to clipboard

Use the default value from remote configuration.

Link copied to clipboard

Local override to force the feature OFF, regardless of remote configuration.

Link copied to clipboard

Local override to force the feature ON, regardless of remote configuration.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns a representation of an immutable list of all enum entries, in the order they're declared.

Link copied to clipboard
expect val name: String
Link copied to clipboard
expect val ordinal: Int

Functions

Link copied to clipboard

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Link copied to clipboard

Returns an array containing the constants of this enum type, in the order they're declared.