Using Banners / MREC with Android

We do not serve banner ads to apps that are opted-out of behavioral targeting.
Banner ads are limited to Android SDKs version 8.0.1 and above.
Banner ads are not supported for Amazon integrations.
ChartboostBanner is a View subclass able to show banner ads. Unlike other ad types, the developer is responsible for integrating the banner with the app UI and presenting it to the user.
Multiple Banners can be displayed at once if desired.
Creating a banner
To create a new banner it is possible to do it in the xml layout file.
​           xmlns:​chartboost​=​"h​ttp://​"
           android:​layout_height​="​ wrap_content"
           chartboost:​size​=​"STANDARD"​ />
The developer is responsible for defining unique location names and using one of the three provided sizes and visual placement in the layout.
The developer needs to create ChartboostBanner object and attach it to the view. View can be customised with LayoutParams. BannerSize object corresponds to the XML size values ChartboostBannerListener can be attached later with setListener function.
//create new banner with:
// - context - required
// - location - required
// - BannerSize - Required
// - ChartboostBannerListener - Optional
ChartboostBanner chartboostBanner = new ChartboostBanner(this, bannerLocation, bannerSize, null);

//Attach object to layout
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)​;
params.gravity = CENTER_HORIZONTAL;
mBannerContainer.addView(chartboostBanner, params);
The developer can detach Banner from the view and destroy the object. In order to do so, use:
Showing banner ads
To make the banner show an ad first, create and present it as seen before, and then call this method:
to cache the ad
and show to make the ad visible
Banner ads sizes
STANDARD – 320 x 50
MREC – 300 x 250
LEADERBOARD – 728 x 90
Auto refreshing
By default a banner will automatically update its content on its own. The refresh default rate is 30s. This means you only need to call bellow method once and the banner will get new ads and show them by itself, gracefully handling errors if they occur. Banners will also be refreshed once clicked.
Manually handling banner refresh
If you decide to disable banner auto-refreshing you can do that by setting
In this case you’ll need to call the cache function to load an ad and implement the corresponding listener method to be notified of when the ad is ready to be shown. Example:
void cacheBanner​()​ {

void onAdCached​(ChartboostCacheEvent event, ChartboostCacheError error) {
    ​if​(error != ​null​) { ;

​​void onAdShown​(ChartboostShowEvent event, ChartboostShowError error)​ {​
    if​(error != ​null​) {
Banner listener
Every banner has an optional listener which can be provided when initialized or assigned afterwards.
Implementing listener methods is the way you can be notified and respond to events related to the banner life-cycle.
These are all the listener methods:
Class name: ChartboostBannerListener
// Called after ad is cached and ready to be shown or indicated reason of failure
void onAdCached​(ChartboostCacheEvent event, ChartboostCacheError error);

// Called after ad is displayed and visible on the screen or indicated reason of failure
void ​​onAdShown​(ChartboostShowEvent event, ChartboostShowError error);

// Called after ad has been clicked or indicated reason of failure
void onAdClicked​(ChartboostClickEvent event, ChartboostClickError error);
  • ChartboostCacheEvent​, ChartboostShowEven​, ChartboostClickEvent​ – object is not null when event performed without any issues.
  • ChartboostCacheError​,​ ChartboostShowError​,​ ChartboostClickError​​ – error object should be null unless there was an issue. The developer should check for both event and error object to determine if flow was successful.
Ad Identifier
All the non-error event objects passed as parameters in delegate method calls include an adID property.
This is a string that uniquely identifies a cached ad. It might help when working with Chartboost to identify faulty creatives.
Public Banner Errors
All errors can be checked in the public code and to check actual error code value, error can be accessed like this:
ChartboostCacheError cacheError = new ChartboostCacheError(ChartboostCacheError.Code.INTERNAL);

ChartboostShowError showError = new ChartboostCacheError(ChartboostShowError.Code.INTERNAL);

ChartboostClickError clickError = new ChartboostClickError(ChartboostClickError.Code.INTERNAL);

Last Updated on January 14, 2022