Feature Flag Decision
A Feature Flag has two states: on and off. Different features are configured for each state. When a user accesses a feature with a Feature Flag applied, the SDK must return the on or off state. You can use the Hackle SDK to make this decision.
isFeatureOn
Pass the Feature Key to the isFeatureOn() method to receive the state result for the user. Then implement logic based on the state.
The example code below passes Feature Key 42.
import io.hackle.android.HackleApp
// Decides the user's state for the Feature Flag with Feature Key 42.
// Returns false (off state) if the state cannot be decided.
val isFeatureOn: Boolean = hackleApp.isFeatureOn(42)
if (isFeatureOn) {
// Logic for the ON state
} else {
// Logic for the OFF state
}import io.hackle.android.HackleApp
// Decides the user's state for the Feature Flag with Feature Key 42.
// Returns false (off state) if the state cannot be decided.
boolean featureOn = hackleApp.isFeatureOn(42);
if (featureOn) {
// Logic for the ON state
} else {
// Logic for the OFF state
}featureFlagDetail
The featureFlagDetail() method works the same as isFeatureOn() but also provides the reason for the state decision. This is useful for checking whether an Override is working correctly, or when the distribution result seems inconsistent with the configured Traffic Allocation.
You must pass the Feature Key as a parameter. The example code below passes Feature Key 42.
The state decision reason is returned in the format SDK_NOT_READY. See the table below for details.
SDK_NOT_READY
The SDK is not ready to use. (e.g., initialization attempted with an invalid SDK Key)
Default state (off)
FEATURE_FLAG_NOT_FOUND
No Feature Flag was found for the provided Feature Key. The Feature Key may be incorrect, or the Feature Flag may be archived.
Default state (off)
FEATURE_FLAG_INACTIVE
The Feature Flag is in the off state.
Default state (off)
INDIVIDUAL_TARGET_MATCH
Matched by Individual Targeting.
State configured by Individual Targeting
TARGET_RULE_MATCH
Matched by User Targeting.
State configured by User Targeting
DEFAULT_RULE
Did not match either Individual Targeting or User Targeting.
State configured by default rule
EXCEPTION
An unknown error occurred.
Default state (off)
Feature Flag Parameters
The
featureFlagDetail()method also returns the parameter values for the state decision.The
FeatureFlagDecisioninstance returned byfeatureFlagDetail()contains aParameterConfigobject with all parameter configuration.Since parameters set on the Hackle Feature Flag screen exist as key-value pairs, you can use the methods below to retrieve parameter values according to the configured parameter type.
You can dynamically change values on the Feature Flag parameter settings screen.
getString
Returns a parameter value configured as STRING or JSON type.
Returns the value configured for False or True based on the state decision.
getInt
Returns a parameter value configured as Number type as an Int.
Returns the value configured for False or True based on the state decision.
getDouble
Returns a parameter value configured as Number type as a Double.
Returns the value configured for False or True based on the state decision.
getLong
Returns a parameter value configured as Number type as a Long.
Returns the value configured for False or True based on the state decision.
getBoolean
Returns a parameter value configured as Boolean type.
Returns the value configured for False or True based on the state decision.
Last updated