Android SDK

If you don’t have an account on your Clutch.io instance yet, you’ll need to do that first. If you don’t have a Clutch.io instance set up yet, follow the steps on the Clutch project README. Otherwise, follow the steps below.

Getting Started

First, download the Clutch library JAR file, and add it to your project. Now, in your project’s main Activity, you should add three calls: one in onCreate, another in onPause, and finally one in onResume. Here’s how it should look:

In your onCreate, call the ClutchAB.setup(Context ctx, String key) method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ClutchAB.setup(this.getApplicationContext()
        "YOUR_APPLICATION_KEY",
        "YOUR_RPC_URL"
    );

    // The rest of your code here, maybe something like:
    // setContentView(R.layout.main);
}

In your onPause, call the ClutchAB.onPause() method:

protected void onPause() {
    super.onPause();
    ClutchAB.onPause();
}

In your onResume, call the ClutchAB.onResume() method:

protected void onResume() {
    super.onResume();
    ClutchAB.onResume();
}

Those three integration points will set everything up, and prepare your code to begin A/B testing.

Normal Tests

The function for running a test is ClutchAB.test(String name, ClutchABTest test). The ClutchABTest object should be an anonymous subclass and you can implement public void A() all the way up to public void J() for up to ten different tests per experiment.

Example:

// Find our login button
final Button loginButton = (Button)findViewById(R.id.login_button);

// Test which color performs better
ClutchAB.test("loginButtonColor", new ClutchABTest() {
    public void A() {
        // Red?
        loginButton.setBackgroundColor(Color.RED);
    }
    public void B() {
        // Or green?
        loginButton.setBackgroundColor(Color.GREEN);
    }
});

Data-driven Tests

The function for running a data-driven test is ClutchAB.test(String name, ClutchABDataTest test). The ClutchABDataTest object should be an anonymous subclass that must implement public void action(JSONObject testData).

Example:

// Find our login button
final Button loginButton = (Button)findViewById(R.id.login_button);

ClutchAB.test("loginButtonTitle", new ClutchABDataTest() {
    public void action(JSONObject testData) {
        loginButton.setText(testData.optString("title"));
    }
});

Goal Reached

The function for noting that a goal was reached is ClutchAB.goalReached(String name), where the argument is the test’s short name.

Example:

public void onNewAccountCreated() {
    // A new account was created, so whatever button color was chosen, worked!
    ClutchAB.goalReached("loginButtonColor");
}

Contents

Previous topic

iOS SDK

Next topic

Screencasts

This Page