# Quick start

The following example assumes that a campaign has already been configured beforehand on the platform and that the Android SDK has been successfully installed in your project.

See how to configure a toggle feature campaign on our [user documentation](/feature-experimentation-and-rollout.md#server-side-experiments) .

See how to install the Flagship Android SDK in your project :[installation](/server-side/sdks/android/android/android-installation.md).

## Step 1 : Initialize the SDK

At the most appropriate location of your Android application, call the **start** function from the **Flagship** class, in order to initialize the Flagship SDK:

```kotlin
import com.abtasty.flagship.main.Flagship
import com.abtasty.flagship.main.FlagshipConfig

suspend fun startFlagshipSDK() {
  
  // Start Flagship SDK
  Flagship.start(
    application,
    ENV_ID,
    API_KEY,
    FlagshipConfig.DecisionApi()
  )
}
```

The SDK starts in [DECISION-API](/server-side/decision-api.md). More options are available in the [SDK configuration](/server-side/sdks/android/android/android-reference.md#flagshipconfig).

{% hint style="info" %}
📘 Environment ID and API Key

Environment id (*ENV\_ID*) and API key (*API\_KEY*) can be found on your Flagship account, in Parameters > Environment & Security.
{% endhint %}

## Step 2 : Create a visitor

Creating a [visitor](/server-side/sdks/android/android/android-reference.md#visitor) using the [newVisitor](/server-side/sdks/android/android/android-reference.md#newvisitor) function from the [Flagship](/server-side/sdks/android/android/android-reference.md#flagship) instance allows you to set relevant data for Flagship to make a decision, including: [Visitor ID](/server-side/glossary.md#visitor-id), [Visitor Context](/server-side/glossary.md#user-context-1), [GDPR Consent](doc:javascript-reference#newvisitor-method), and [Authentication status](/server-side/sdks/android/android/android-reference.md#authenticate).

For example, if you want to enable a specific feature for all your VIP visitors, you'll need to add this data as an attribute into the visitor context (key-value pair): `isVIP: true`.

Based on your targeting criteria defined in your use-case (`isVIP == true`), Flagship will make the decision and show your feature to visitors when they have `isVIP: true` in their context.

```kotlin
import com.abtasty.flagship.main.Flagship
import com.abtasty.flagship.main.FlagshipConfig

suspend fun startFlagshipSDK() {
  
    // Start Flagship SDK
    Flagship.start(
      application,
      ENV_ID,
      API_KEY,
      FlagshipConfig.DecisionApi()
    )
    
    // Create visitor with context
    val visitor = Flagship.newVisitor("visitor_uuid", true)
    	.context(hashMapOf("isVIP" to true))
    	.build()
}

```

## Step 3 : Manage flags

Once a visitor is created with a given context, you have to fetch flags, using the [fetchFlags](/server-side/sdks/android/android/android-reference.md#fetchflags) method, to assign campaigns and its flags to this visitor.

When flag fetching completes, you are ready to process visitor's flags and read their [values](/server-side/sdks/android/android/android-reference.md#getflag) from the returned Flag object based on the desired flag key.

This object includes methods to retrieve the flag value, its metadata, expose the flag, verify the flag's existence, and get the flag status.

```kotlin
import com.abtasty.flagship.main.Flagship
import com.abtasty.flagship.main.FlagshipConfig

suspend fun startFlagshipSDK() {
  
    // Start Flagship SDK
    Flagship.start(
      application,
      ENV_ID,
      API_KEY,
      FlagshipConfig.DecisionApi()
    )
    
    // Create visitor with context
    val visitor = Flagship.newVisitor("visitor_uuid", true)
    	.context(hashMapOf("isVIP" to true))
    	.build()
      
    // Retrieve visitor assigned Flags according to its context.
    visitor.fetchFlags().await()
    
    
    // Get the current Flag value for 'isVipFeatureEnabled' Flag.
    val isVipFeatureEnabled = visitor.getFlag("isVipFeatureEnabled").value(false)
    
    // Process the Flag value in your code
    when (isVipFeatureEnabled) {
      true -> { 
        // display your vip feature
      }

      else -> { 
        // hide your vip feature
      }
    }
}
```

{% hint style="info" %}
📘 Flag exposure

The SDK assumes that the visitor has been exposed to the flag by default when `flag.getValue()` is called, so it sends the flag exposure hit on Flagship servers. This behavior can be changed and exposure be sent manually, [Click here for more details](/server-side/sdks/android/android/android-reference.md#getflag).
{% endhint %}

## Step 4 : Send tracking hit events

Finally, send hits to Flagship using the [sendHit](/server-side/sdks/android/android/android-reference.md#sendhit) method of the [**visitor instance**](https://docs.abtasty.com/server-side/sdks/android/android/pages/eNbizeI7ZgjeBf0RCfot#visitor.instance). These hits help validate your objectives (KPIs) set up in your campaign.\\

```kotlin
import com.abtasty.flagship.main.Flagship
import com.abtasty.flagship.main.FlagshipConfig
import com.abtasty.flagship.hits.Event

suspend fun startFlagshipSDK() {
  
  
    // Start Flagship SDK
    Flagship.start(
      application,
      ENV_ID,
      API_KEY,
      FlagshipConfig.DecisionApi()
    )
    
    // Create visitor with context
    val visitor = Flagship.newVisitor("visitor_uuid", true)
    	.context(hashMapOf("isVIP" to true))
    	.build()
      
    // Retrieve visitor assigned Flags according to its context.
    visitor.fetchFlags().await()
    
    
    // Get the current Flag value for 'isVipFeatureEnabled' Flag.
    val isVipFeatureEnabled = visitor.getFlag("isVipFeatureEnabled").value(false)
    
    // Process the Flag value in your code
    when (isVipFeatureEnabled) {
      true -> { 
        // display your vip feature
      }

      else -> { 
        // hide your vip feature
      }
    }
    
    // Send tracking event when a visitor click on the vip feature
    visitor.sendHit(
      Event(Event.EventCategory.ACTION_TRACKING, "VIP_FEATURE_CTA")
        .withEventLabel("click_on_vip_feature")
    )
}

```

## Step 5 : Reporting

{% hint style="success" %}
👍 Congrats, you have successfully implemented the Flagship Android SDK.

Check your campaign reporting.
{% endhint %}


---

# 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.abtasty.com/server-side/sdks/android/android/android-quick-start.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.
