# Feature Flag Decision

{% hint style="info" %}
This feature is supported in Android SDK 2.0.0 and above.
{% endhint %}

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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp

// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
val isFeatureOn: Boolean = hackleApp.isFeatureOn(42, "ae03e1adf")

if (isFeatureOn) {
    // ON 기능
} else {
    // OFF 기능
}
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp

// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
boolean featureOn = hackleApp.isFeatureOn(42);

if (featureOn) {
    // ON 기능
} else {
    // OFF 기능
}
```

{% endtab %}
{% endtabs %}

## 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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision

// 상태 결정 상세
val decision = hackleApp.featureFlagDetail(42)

// 기능 on/off 여부
val featureOn = decision.isOn()

// 상태 결정 사유
val reason = decision.getReason()
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision

// 상태 결정 상세
FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);

// 기능 on/off 여부
boolean featureOn = decision.isOn();

// 상태 결정 사유
DecisionReason reason = decision.getReason();
```

{% endtab %}
{% endtabs %}

The state decision reason is returned in the format **`SDK_NOT_READY`**. See the table below for details.

<table><thead><tr><th width="233.71875">Decision Reason</th><th width="370.8046875">Description</th><th>Distribution Result</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td>The SDK is not ready to use.<br>(e.g., initialization attempted with an invalid SDK Key)</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_NOT_FOUND</code></td><td>No Feature Flag was found for the provided Feature Key.<br>The Feature Key may be incorrect, or the Feature Flag may be archived.</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_INACTIVE</code></td><td>The Feature Flag is in the off state.</td><td>Default state<br>(off)</td></tr><tr><td><code>INDIVIDUAL_TARGET_MATCH</code></td><td>Matched by Individual Targeting.</td><td>State configured by<br>Individual Targeting</td></tr><tr><td><code>TARGET_RULE_MATCH</code></td><td>Matched by User Targeting.</td><td>State configured by User Targeting</td></tr><tr><td><code>DEFAULT_RULE</code></td><td>Did not match either Individual Targeting or User Targeting.</td><td>State configured by<br>default rule</td></tr><tr><td><code>EXCEPTION</code></td><td>An unknown error occurred.</td><td>Default state<br>(off)</td></tr></tbody></table>

## Feature Flag Parameters

{% hint style="info" %}
This feature is supported in Android SDK 2.9.0 and above.
{% endhint %}

* The `featureFlagDetail()` method also returns the parameter values for the state decision.
* The `FeatureFlagDecision` instance returned by `featureFlagDetail()` contains a `ParameterConfig` object 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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

val decision: FeatureFlagDecision = hackleApp.featureFlagDetail(42)
val config: ParameterConfig = decision.config

val strValue: String = decision.getString("parameter_key_string_type", "defaultValue")
val strValueInConfig: String = config.getString("parameter_key_string_type", "defaultValue")

val jsonValue: String = decision.getString("parameter_key_json_type", "defaultValue")
val jsonValueInConfig: String = config.getString("parameter_key_json_type", "defaultValue")
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);
ParameterConfig config = decision.getConfig();

String strValue = decision.getString("parameter_key_string_type", "defaultValue");
String strValueInConfig = config.getString("parameter_key_string_type", "defaultValue");

String jsonValue = decision.getString("parameter_key_json_type", "defaultValue");
String jsonValueInConfig = config.getString("parameter_key_json_type", "defaultValue");
```

{% endtab %}
{% endtabs %}

### 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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

val decision: FeatureFlagDecision = hackleApp.featureFlagDetail(42)
val config: ParameterConfig = decision.config

val intValue: Int = decision.getInt("parameter_key_number_type", 0)
val intValueInConfig: Int = config.getInt("parameter_key_number_type", 0)
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);
ParameterConfig config = decision.getConfig();

int intValue = decision.getInt("parameter_key_number_type", 0);
int intValueInConfig = config.getInt("parameter_key_number_type", 0);
```

{% endtab %}
{% endtabs %}

### 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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

val decision: FeatureFlagDecision = hackleApp.featureFlagDetail(42)
val config: ParameterConfig = decision.config

val doubleValue: Double = decision.getDouble("parameter_key_number_type", 0.0)
val doubleValueInConfig: Double = config.getDouble("parameter_key_number_type", 0.0)
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);
ParameterConfig config = decision.getConfig();

double doubleValue = decision.getDouble("parameter_key_number_type", 0.0);
double doubleValueInConfig = config.getDouble("parameter_key_number_type", 0.0);
```

{% endtab %}
{% endtabs %}

### 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.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

val decision: FeatureFlagDecision = hackleApp.featureFlagDetail(42)
val config: ParameterConfig = decision.config

val longValue: Long = decision.getLong("parameter_key_number_type", 0L)
val longValueInConfig: Long = config.getLong("parameter_key_number_type", 0L)
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);
ParameterConfig config = decision.getConfig();

long longValue = decision.getLong("parameter_key_number_type", 0L);
long longValueInConfig = config.getLong("parameter_key_number_type", 0L);
```

{% endtab %}
{% endtabs %}

### getBoolean

* Returns a parameter value configured as Boolean type.
* Returns the value configured for False or True based on the state decision.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

val decision: FeatureFlagDecision = hackleApp.featureFlagDetail(42)
val config: ParameterConfig = decision.config

val booleanValue: Boolean = decision.getBoolean("parameter_key_boolean_type", false)
val booleanValueInConfig: Boolean = config.getBoolean("parameter_key_boolean_type", false)
```

{% endtab %}

{% tab title="Java" %}

```java
import io.hackle.android.HackleApp
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.ParameterConfig

FeatureFlagDecision decision = hackleApp.featureFlagDetail(42);
ParameterConfig config = decision.getConfig();

boolean booleanValue = decision.getBoolean("parameter_key_boolean_type", false);
boolean booleanValueInConfig = config.getBoolean("parameter_key_boolean_type", false);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/android/android-feature-flag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
