Multi-size banner placements are similar to sticky banners, but can present banners of varying sizes. For instance, it is possible to display a banner of the standard size 320x53, followed by a medium rectangle of size 300x250 within the same placement.
Create Placement
It will depend on the server-side configuration on the Dashboard and what actual sizes are getting delivered to your placement.
val placement = AATKit.createMultiSizeBannerPlacement("<PLACEMENT_NAME>")
The green background is an ad container (FrameLayout), into which the placement view is added by the app. It represents the space that the app reserves for a multi-size banner placement view (the green colour is just used here for explanatory purposes).
To automatically load (and reload) the sticky banner placement enable auto-reload. If you do not set the refresh time interval seconds explicitly, AATKit will
Reload every 30 seconds (if no refresh time interval is set on the Dashboard)
Respect the refresh time interval setting of the Dashboard (which means, you can configure the interval without having to re-publish your app)
// reload the banner placement every 30 seconds.
placement.startAutoReload();
// OR set refresh time manually
placement.startAutoReload(45);
// reload the banner placement every 30 seconds.
placement.startAutoReload()
// OR set refresh time manually
placement.startAutoReload(45)
The minimum refresh time is 30 seconds.
This needs to stop the auto-reload when it is no longer needed (e.g. if the view controller presenting ads will disappear):
placement.stopAutoReload();
placement.stopAutoReload()
Manual Load
To manually load the sticky banner placement:
placement.reload();
// Or using force load
placement.reload(true);
placement.reload()
// Or using force load
placement.reload(true)
Force Load
false (default): reload() will respect the current time interval.
true: reload() will immediately reload (irrespective of the fact when the last ad was loaded). This can be useful if the same sticky banner placement is used on various different pages of the app and you want to load a new ad every time the user navigates to another page (while still using auto-reloading).
Destroy old banner
When you no longer need a multiSizeBanner (for example when moving to a different activity), you have to destroy it manually by removing it from your view and calling the "destroy" method:
[remove loadedMultiSizeBanner from your layout]
loadedMultiSizeBanner.destroy();
loadedMultiSizeBanner = null;
[remove loadedMultiSizeBanner from your layout]
loadedMultiSizeBanner.destroy()
loadedMultiSizeBanner = null
Complete Code Example
private MultiSizeBannerPlacement placement = AATKit.createMultiSizeBannerPlacement("<PLACEMENT_NAME>");
private BannerPlacementLayout loadedBanner = null;
@Override
protected void onResume() {
super.onResume();
// [IMPORTANT] Notify AATKit about activity lifecycle
AATKit.onActivityResume(this);
// Set placement listener to listen to the callbacks
placement.setListener(this);
// reload the banner placement every 30 seconds.
placement.startAutoReload();
// OR set refresh time manually
placement.startAutoReload(30);
}
@Override
protected void onPause() {
// [IMPORTANT] Stop placement auto-reload
placement.stopAutoReload();
// [IMPORTANT] Notify AATKit about activity lifecycle
AATKit.onActivityPause(this);
super.onPause();
}
// MultiSizeBannerPlacementListener implementation
@Override
public void onPauseForAd(@NonNull Placement placement) {
// App is paused after banner got clicked
}
@Override
public void onResumeAfterAd(@NonNull Placement placement) {
// Back to the app after clicking on the ad
}
@Override
public void onHaveAdWithBannerView(@NonNull Placement placement, @NonNull BannerPlacementLayout bannerView) {
//clear previous banner
bannerFrame.removeAllViews();
if (loadedBanner != null) {
loadedBanner.destroy();
}
//present new banner
loadedBanner = bannerView;
bannerFrame.addView(loadedBanner);
}
@Override
public void onNoAd(@NonNull Placement placement) {
// The placement could not load a new ad
}
private val placement = createMultiSizeBannerPlacement("<PLACEMENT_NAME>")
private var loadedBanner: BannerPlacementLayout? = null
protected override fun onResume() {
super.onResume()
// [IMPORTANT] Notify AATKit about activity lifecycle
onActivityResume(this)
// Set placement listener to listen to the callbacks
placement.listener = this
// reload the banner placement every 30 seconds.
placement.startAutoReload()
// OR set refresh time manually
placement.startAutoReload(30)
}
protected override fun onPause() {
// [IMPORTANT] Stop placement auto-reload
placement.stopAutoReload()
// [IMPORTANT] Notify AATKit about activity lifecycle
onActivityPause(this)
super.onPause()
}
// MultiSizeBannerPlacementListener implementation
fun onPauseForAd(placement: Placement) {
// App is paused after banner got clicked
}
fun onResumeAfterAd(placement: Placement) {
// Back to the app after clicking on the ad
}
fun onHaveAdWithBannerView(placement: Placement, bannerView: BannerPlacementLayout) {
//clear previous banner
bannerFrame.removeAllViews()
loadedBanner?.destroy()
//present new banner
loadedBanner = bannerView
bannerFrame.addView(loadedBanner)
}
fun onNoAd(placement: Placement) {
// The placement could not load a new ad
}