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
Properties
Functions
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.)
Returns an array containing the constants of this enum type, in the order they're declared.