Generated banner for Feature Flags Android
Generated logo for Feature Flags Android

Feature Flags Android

PostHogOfficialCreated by PostHog

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • No issues found

From the author

PostHog feature flags for Android applications
— the description by PostHog

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides guidance and best practices for implementing PostHog feature flags within Android applications. It covers the necessary SDK installation, configuration in the Application class, and methods for evaluating both boolean and multivariate flags. The skill emphasizes secure practices, such as using environment variables for API keys, and provides patterns for initializing the PostHog client to ensure efficient flag management.

What it does

  • Guides the installation of the PostHog Android SDK via Gradle.
  • Provides patterns for initializing PostHog in the Application class.
  • Demonstrates how to evaluate boolean feature flags in Kotlin.
  • Shows how to implement multivariate feature flags for specific user variants.
  • Offers best practices for flag management and environment variable usage.
  • Integrates with PostHog MCP tools for direct flag management.

When to use it

  • When you need to perform phased rollouts of new features in an Android app.
  • When you want to run A/B tests or experiments on specific user segments.
  • When you need to toggle features on or off remotely without a new app release.
  • When you are setting up a new Android project and want to include feature flagging capabilities.

Advantages

  • Enables safer feature releases through gradual rollouts.
  • Allows for remote configuration of app behavior.
  • Supports data-driven decision making via experiments.
  • Promotes clean code by separating feature logic from deployment.

Usage examples

“How do I check if a feature flag is enabled in my Android app?”
The agent will provide the Kotlin code snippet using PostHog.isFeatureEnabled('flag-key') and explain how to handle the boolean result.
“Show me how to initialize PostHog in my Android Application class.”
The agent will provide a sample implementation of the Application class, demonstrating the correct use of PostHogAndroid.setup() within the onCreate() method.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/posthog/feature-flags-android/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip feature-flags-android.zip -d .agents/skills

Documentation by PostHog

PostHog feature flags for Android

This skill helps you add PostHog feature flags to Android applications.

Reference files

  • references/android.md - Android feature flags installation - docs

  • references/adding-feature-flag-code.md - Adding feature flag code - docs

  • references/best-practices.md - Feature flag best practices - docs

Consult the documentation for API details and framework-specific patterns.

Key principles

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them.

  • Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.

  • Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.

  • Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.

PostHog MCP tools

Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.

Framework guidelines

  • Adapt dependency configuration to the appropriate build.gradle(.kts) file according to the project gradle version

  • Call PostHogAndroid.setup() only once in the Application class's onCreate() method, so it's initialized as early as possible and only once.

  • Initialize PostHog in the Application class's onCreate() method

  • Ensure every activity has a android:label to accurately track screen views.

Files

references/android.md

Android feature flags installation - Docs

  1. 1

    Install the dependency

    Required

    Add the PostHog Android SDK to your build.gradle dependencies:

    build.gradle

    PostHog AI

    dependencies {
        implementation("com.posthog:posthog-android:3.+")
    }
  2. 2

    Configure PostHog

    Required

    Initialize PostHog in your Application class:

    SampleApp.kt

    PostHog AI

    class SampleApp : Application() {
        companion object {
            const val POSTHOG_PROJECT_TOKEN = "<ph_project_token>"
            const val POSTHOG_HOST = "https://us.i.posthog.com"
        }
        override fun onCreate() {
            super.onCreate()
            // Create a PostHog Config with the given project token and host
            val config = PostHogAndroidConfig(
                apiKey = POSTHOG_PROJECT_TOKEN,
                host = POSTHOG_HOST
            )
            // Setup PostHog with the given Context and Config
            PostHogAndroid.setup(this, config)
        }
    }
  3. 3

    Send events

    Recommended

    Once installed, PostHog will automatically start capturing events. You can also manually send events to test your integration:

    Kotlin

    PostHog AI

    import com.posthog.PostHog
    PostHog.capture(
        event = "button_clicked",
        properties = mapOf(
            "button_name" to "signup"
        )
    )
  4. 4

    Evaluate boolean feature flags

    Required

    Check if a feature flag is enabled:

    Kotlin

    PostHog AI

    val isMyFlagEnabled = PostHog.isFeatureEnabled("flag-key")
    if (isMyFlagEnabled) {
        // Do something differently for this user
        // Optional: fetch the payload
        val matchedFlagPayload = PostHog.getFeatureFlagPayload("flag-key")
    }
  5. 5

    Evaluate multivariate feature flags

    Optional

    For multivariate flags, check which variant the user has been assigned:

    Kotlin

    PostHog AI

    val enabledVariant = PostHog.getFeatureFlag("flag-key")
    if (enabledVariant == "variant-key") { // replace 'variant-key' with the key of your variant
        // Do something differently for this user
        // Optional: fetch the payload
        val matchedFlagPayload = PostHog.getFeatureFlagPayload("flag-key")
    }
  6. 6

    Running experiments

    Optional

    Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.

  7. 7

    Next steps

    Recommended

    Now that you're evaluating flags, continue with the resources below to learn what else Feature Flags enables within the PostHog platform.

    ResourceDescription
    Creating a feature flagHow to create a feature flag in PostHog
    Adding feature flag codeHow to check flags in your code for all platforms
    Framework-specific guidesSetup guides for React Native, Next.js, Flutter, and other frameworks
    How to do a phased rolloutGradually roll out features to minimize risk
    More tutorialsOther real-world examples and use cases
Community questions

Ask a question

Was this page useful?

HelpfulCould be better

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an MCP server

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
PostHog
Publisher
PostHog (Official)
Source
PostHog/skills · skills/posthog/feature-flags/skills/android · commit a5d30e7
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
PostHog/skills

AutoGineer is not affiliated with or endorsed by PostHog.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download feature-flags-android.zip