Example Kotlin Android application for CloudBees platform feature management

3 minute read

Use this example application to integrate with CloudBees platform and test feature management. After integrating, observe the application display changes in response to updates you make to flag values in {KPRODUCT}

In the example Kotlin application, the ROX SDK is already set up, and feature flags are already coded in.

Get started with the android-fm-example project

To get started with the android-fm-example project, follow these steps:

  1. Clone the repository:

  2. Using Git, clone the android-fm-example repository to your local machine:

    git clone git@github.com:cloudbees-io/android-fm-example.git
  3. Build and open the project:

    1. In Android Studio, select File  New  Import Project and open the cloned repository.

    2. If you are using an emulator, start the emulator.

  4. Locate and copy the SDK key:

    1. Navigate to Feature management  Flags.

    2. Select an application.

    3. Select COPY next to the SDK key on the page.

      If you do not see an SDK key:

      1. Navigate to Feature management  Flags.

      2. Select Installation instructions in the upper-right corner.

      3. Follow the installation instructions to complete the installation.

      4. The SDK key will appear once an application is linked to an environment.

      5. Close the installation instructions, and copy the SDK Key.

  5. Reopen your project in Android Studio.

  6. You must add the SDK key to your Cloudbees account: In the AndroidManifest.xml file, replace the <Your Cloudbees SDK Key> with your corresponding API key:

    <meta-data android:name="rox.apiKey" android:value="<Your Cloudbees SDK Key>" />
  7. In Android Studio, select android-studio-run to run the android-fm-example application.

    After running the application, the flags displayed in Feature flags in the example application. are automatically added to your Flags dashboard in CloudBees platform.

View the imported flags

Now that your application is running:

  1. In CloudBees platform, select Feature management.

  2. Select your example application to display the available flags as shown in the table below.

    Table 1. Feature flags in the example application.
    Flag name Flag type Description

    showMessage

    Boolean

    Turns the message on or off.

    message

    String

    Sets the message text.

    fontSize

    Number (Int for Python)

    Sets the message font size in pixels. The flag value has the following variations: 12, 16, or 24.

    fontColor

    String

    Sets the message font color. The flag value has the following variations: red, green, or blue.

Apply changes to flags in the UI

  1. Select Feature management.

  2. Select the application.

  3. Select Vertical ellipsis next to the flag you want to configure.

  4. Select Configure.

  5. Select the Environment.

  6. Update a flag value and save your changes.

  7. Set the Configuration status to On.

  8. The updated flag value is reflected in the display of the application.

Use the application with multiple SDK keys

Run multiple instances of the SDK in a single application, each with its own SDK key and environment. Each instance is fully isolated. Use this when you need to read or compare flags across environments without redeploying, support multi-tenant routing, or combine server-side and client-side evaluations in one application.

To use multiple SDK keys in the example Kotlin Android application, follow these steps:

  1. Retrieve the SDK keys for the environments you’ll use.

  2. Initialize a separate SDK instance for each key.

  3. Decide how to route requests to instances (for example, by tenant, region, or environment selector).

  4. Perform register/fetch/stream setup on each instance as required by your SDK.

  5. Evaluate flags using the selected instance. Pass a consistent user/context object for accurate targeting.

  6. Tag logs or metrics by instance, and shut down instances you no longer need.

For more information about using multiple SDK keys, refer to Manage multiple SDK keys in your application.

Documentation reference

Refer to Install the SDK for more information