Skip to content

Instantly share code, notes, and snippets.

@mauerbac
Last active November 22, 2021 19:48
Show Gist options
  • Save mauerbac/64d2c638b72e38de603f511601dd2b91 to your computer and use it in GitHub Desktop.
Save mauerbac/64d2c638b72e38de603f511601dd2b91 to your computer and use it in GitHub Desktop.
Full code snippet for Optimizely's Android Getting Started Guide
// MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.optimizely.ab.android.sdk.OptimizelyClient;
import com.optimizely.ab.android.sdk.OptimizelyManager;
import com.optimizely.ab.android.sdk.OptimizelyStartListener;
import com.optimizely.ab.config.Variation;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OptimizelyManager optimizelyManager = OptimizelyManager.builder("project_id")
.withEventHandlerDispatchInterval(30, TimeUnit.SECONDS)
.withDataFileDownloadInterval(30, TimeUnit.SECONDS)
.build();
optimizelyManager.initialize(this, new OptimizelyStartListener() {
@Override
public void onStart(OptimizelyClient optimizely) {
Variation variation = optimizely.activate("my_experiment", "currentUser");
System.out.println(variation);
optimizely.track("my_conversion", "currentUser");
}
});
}
}
@sumeetpanchal
Copy link

will the initialization process not make the onCreate of the Activity to run slow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment