Android SDK 6.x Upgrade

Key Changes

Below is an overview of the changes you need to be aware of in 6.x when upgrading from a previous (4.x) SDK version:

SDK initialization API and its required parameters have changed

All public methods are now static, so rather than using instance calls, you’ll call the methods on the class object directly (e.g., you’d replace this.cb.showInterstitial(location); with Chartboost.showInterstitial(location); and omit any instance variable declarations (e.g., remove private Chartboost cb;)

ChartboostDelegate is not an interface anymore, rather it is an abstract class. This means you don’t need to know (or implement) ahead of time the delegate callbacks that you need.

To create delegates, do not pass ‘null’ or a delegate object to this.cb.onCreate(...) anymore. It has its own class method, Chartboost.setDelegate(cb_delegate); which should be placed before Chartboost.onCreate(this); (details below).

Method name changes on all has<CachedObject> methods to better clarify their meanings, e.g. hasCachedInterstitial, hasCachedVideo etc. are now hasInterstitial, hasRewardedVideo. These are static boolean methods that take a String location parameter and return true if cached content exists for the location.

New: Activity callbacks added: onPause() and onResume().

New: setAutoCacheAds(boolean autoCacheAds). Read below for more info.

There is no longer a CBPreferences, so please remove any instance calls for it: this.cbPref = CBPreferences.getInstance(); All impressions now use activities. Be sure to add the following entry in your AndroidManifest.xml file:

If used, the overriden public method for declaring whether interstitials are shown in a user’s first session shouldRequestInterstitialsInFirstSession() needs to be replaced with the setter method Chartboost.setShouldRequestInterstitialsInFirstSession(boolean shouldRequest);

If any activity in which you display Chartboost impressions can rotate between different orientations, you should add the following attribute to the activity in the AndroidManifest.xml file in order to achieve smooth video playback during orientation changes:

android:configChanges="keyboardHidden|orientation|screenSize"

Update the Chartboost SDK initialization in your launcher activity class so that the Chartboost callbacks and API calls can be made. There are two choices for initialization:

You can let the SDK handle this for you by simply extending ChartboostActivity. This removes the need for you to override any activity lifecycle methods such as onCreate, so you can simply call Chartboost.OnCreate(). SKIP TO STEP 11.

You can extend the application’s main Activity explicitly (continue following steps 7 through 8). See example:

Important: All your interstitial and video calls are static. You must pass in the location string to every call, null is no longer available. If you don’t pass in the location, the SDK won’t fetch any ads. You can use the CBLocation interface class to get a list of default location constants as well as define your own. Once a location is used, it will be added to your dashboard where you can customize settings for it.

Back in step (7) you may have noticed Chartboost.setDelegate(delegate). Note: we do not pass ‘null‘ or a delegate object to an overridden onCreate() anymore to create delegates, since it has its own class method now. Call the method before calling Chartboost.onCreate(this) during initialization.

The parameter it takes is a delegate object, which allows you to respond to the events you are interested in by overriding the methods of your choice. Simply supply an object of the abstract class ChartboostDelegate as the parameter:

private ChartboostDelegate cb_delegate = new ChartboostDelegate() {
//Override the Chartboost delegate callbacks you wish to track and control
};

This new method eliminates the need to extend from ChartboostDefaultDelegate as in previous versions of the SDK.

You can choose to have your activities that use Chartboost extend from ChartboostActivity instead of Activity. Read more about this in our README.md. Important: If you use this integration method, you must initialize Chartboost with the method Chartboost.startWithAppId()before calling super.onCreate(). If you do not, an exception will be thrown, as the SDK needs to be initialized first before the SDK calls Chartboost.onCreate() internally. Example:

Age Gate

method to handle Age Gate functionality, that method has now been updated to:

public void didPauseClickForConfirmation(Activity activity)

Dive deeper

Java API docs are provided along with SDK and a sample app.

Check out the code inside CBSample for examples.

If you plan on using Proguard, add the following to your proguard.cfg file (also make sure you follow Proguard instructions for the Google Play Services library):

-keep class com.chartboost.** { *; }

Questions?

We want to your SDK integration be as smooth as possible, so that you can spend more of your time developing awesome games! If you encounter any issues, do not hesitate to contact our support team and we will be happy to help.