Quickstart by stack

Android Quickstart

Install the Kotlin SDK from Maven Central, read a flag in an Android app, and target users with context.

Prerequisites

  • JDK 11 or later, Kotlin 2.0 or later, and Android API level 21 or later.
  • A mobile key (prefixed mob_) from your environment. Keys in an app bundle can be extracted by anyone, so never ship a server key (srv_) in an app.
  • A flag key you can test in a non-production environment.
Install with Gradle (Kotlin DSL) kotlin

dependencies {
    implementation("com.zenmanage:zenmanage-kotlin:1.0.0")
}

The Groovy DSL works too: implementation 'com.zenmanage:zenmanage-kotlin:1.0.0'. The SDK is published to Maven Central, so no extra repository is needed.

Initialize and evaluate kotlin

import com.zenmanage.kotlin.Zenmanage
import com.zenmanage.kotlin.config.ConfigBuilder

val config = ConfigBuilder.create()
    .withEnvironmentToken("mob_your_mobile_key_here")
    .build()

val zenmanage = Zenmanage(config)

val enabled = zenmanage.flags()
    .single("new-dashboard", false)
    .isEnabled()

if (enabled) {
    showNewDashboard()
} else {
    showOldDashboard()
}

Safe defaults

The default you pass to single is what you get when the flag doesn't exist or the rules can't be loaded, such as an offline device with nothing cached or a wrong key. Reading a flag evaluates the rules on the device, so it never waits on a per-flag network call.

One instance per app

Create a single Zenmanage when your app starts, such as in your Application subclass, and share it. It keeps the loaded rules in memory, so build it once instead of per screen.

Target a user with context kotlin

import com.zenmanage.kotlin.context.Attribute
import com.zenmanage.kotlin.context.Context

val context = Context.single("user", "user-123", "Alice")
    .addAttribute(Attribute("country", listOf("US")))

val premium = zenmanage.flags()
    .withContext(context)
    .single("premium-dashboard", false)
    .isEnabled()
Run an A/B test with a string flag kotlin

val variant = zenmanage.flags()
    .withContext(context)
    .single("checkout-flow", "control")
    .asString()

when (variant) {
    "one-page" -> showOnePageCheckout()
    else -> showMultiPageCheckout()
}
Provide defaults for several flags kotlin

import com.zenmanage.kotlin.flags.DefaultsCollection

val defaults = DefaultsCollection.fromMap(
    mapOf(
        "new-ui" to true,
        "api-version" to "v2",
        "max-items" to 100
    )
)

val version = zenmanage.flags()
    .withDefaults(defaults)
    .single("api-version")
    .asString()
Read a JSON value kotlin

val config = zenmanage.flags()
    .single("checkout-config", mapOf("maxItems" to 10, "theme" to "dark"))
    .asJson()

Stable percentage rollouts

The SDK hashes the rollout salt and your context identifier into a bucket from 0 to 99, so a user stays in or out of a rollout across launches. Pass a stable identifier, such as your user ID, in the context.

Typed values

Boolean, string, number, and JSON flags each have a matching accessor: isEnabled(), asString(), asNumber(), and asJson(). A JSON object decodes to a map and a JSON array decodes to a list.

Mobile keys in the app

Use a mob_ key in the app. Client keys (cli_) are rejected. Server keys (srv_) are accepted for Kotlin/JVM backends, so keep those on your server.

Kotlin and Java

The SDK is written in Kotlin and built for Java interop, so Java code can call the same API. Use it from Android apps or from Kotlin/JVM backends.

Next step

Take the next integration step in your own stack.

Start with the quickstart that matches your runtime, then return to the reference pages when you need exact request and payload details.

Language and framework names and logos shown above are trademarks or registered trademarks of their respective owners. Their use here is for identification purposes only and does not imply endorsement of, or affiliation with, Zenmanage.