App open ads are a special fullscreen ad format (created by Google) intended for publishers wishing to monetize their app loading screens (“splash screens”). App open ads can be closed at any time, and are designed to be shown when your users bring your app to the foreground.
Create Placement
You need to create the AppOpen placement as soon as the app becomes active in the applicationDidBecomeActive() method in your AppDelegate.
val placement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>")
Listen to Callbacks (Optional)
Through the use of AppOpenPlacementListener, you can listen to the different placement callbacks.
placement.setListener(this);
placement.listener =this
Request Ad
After creating the placement you need to start placement auto-reloading to get an ad as soon as possible.
@OverrideprotectedvoidonResume() { super.onResume();// [IMPORTANT] Notify AATKit about activity lifecycleAATKit.onActivityResume(this);// Start autoreloading the placement.placement.startAutoReload();}
overridefunonResume() {super.onResume()// [IMPORTANT] Notify AATKit about activity lifecycle AATKit.onActivityResume(this)// Start autoreloading the placement. placement?.startAutoReload()}
Request Ad (In Loading Screen)
App Open Placement is meant to monetize your App Loading screen, so the most proper place to display the Ad is in your own Loading Activity, so while the user is waiting for your App to be ready to use. If AATKit has successfully obtained an Ad you should display it before sending the user to the main content. To do so you will need your LoadingActivity to implement the AppOpenPlacementLitener interface:
privateAppOpenAdPlacement placement =AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>");@OverrideprotectedvoidonResume() { super.onResume();// [IMPORTANT] Notify AATKit about activity lifecycleAATKit.onActivityResume(this);// Set placement listener to listen to the callbacksplacement.setListener(this);// Start autoreloading the placement.placement.startAutoReload();}@OverrideprotectedvoidonPause() {// [IMPORTANT] Stop placement autoreloadplacement.stopAutoReload();// [IMPORTANT] Notify AATKit about activity lifecycleAATKit.onActivityPause(this); super.onPause();}// AppOpenPlacementListener@OverridepublicvoidonPauseForAd(@NonNullPlacement placement) {// Ad has been displayed on the screen}@OverridepublicvoidonResumeAfterAd(@NonNullPlacement placement) {// Back to the app}@OverridepublicvoidonHaveAd(@NonNullPlacement placement) {// The placement has loaded a new ad}@OverridepublicvoidonNoAd(@NonNullPlacement placement) {// The placement could not load a new ad}
privateval placement =createAppOpenAdPlacement("<PLACEMENT_NAME>")overridefunonResume() {super.onResume()// [IMPORTANT] Notify AATKit about activity lifecycle AATKit.onActivityResume(this)// Set placement listener to listen to the callbacks placement?.listener =this// Start autoreloading the placement. placement?.startAutoReload()}overridefunonPause() {// [IMPORTANT] Stop placement autoreload placement?.stopAutoReload()// [IMPORTANT] Notify AATKit about activity lifecycle AATKit.onActivityPause(this)super.onPause()}// AppOpenPlacementListeneroverridefunonPauseForAd(placement: Placement) {// Ad has been displayed on the screen}overridefunonResumeAfterAd(placement: Placement) {// Back to the app}overridefunonHaveAd(placement: Placement) {// The placement has loaded a new ad}overridefunonNoAd(placement: Placement) {// The placement could not load a new ad}
After the user closes the Ad you should send the user to your app's main content, you will get notified when the fullscreen ad is closed in onResumeAfterAd listener method.
Display Ad
You should display that ad at the start of the app session by calling show() method. If the AppOpen placement has a ready ad, It will present it.
placement.show();
placement.show()
Complete Code Example
privateAppOpenAdPlacement placement =AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>");@OverrideprotectedvoidonResume() { super.onResume();// [IMPORTANT] Notify AATKit about activity lifecycleAATKit.onActivityResume(this);// Start autoreloading the placement.placement.startAutoReload();// Display loaded ad (if available)placement.show();}@OverrideprotectedvoidonPause() {// [IMPORTANT] Stop placement autoreloadplacement.stopAutoReload();// [IMPORTANT] Notify AATKit about activity lifecycleAATKit.onActivityPause(this); super.onPause();}
privateval placement =createAppOpenAdPlacement("<PLACEMENT_NAME>")overridefunonResume() {super.onResume()// [IMPORTANT] Notify AATKit about activity lifecycle AATKit.onActivityResume(this)// Start autoreloading the placement. placement?.startAutoReload()// Display loaded ad (if available) placement?.show()}overridefunonPause() {// [IMPORTANT] Stop placement autoreload placement?.stopAutoReload()// [IMPORTANT] Notify AATKit about activity lifecycle AATKit.onActivityPause(this)super.onPause()}
Loading Screen
The above code example assumes that you only show app open ads when users foreground your app after it is suspended in memory. So, if the user launches the app either for the first time since booting or after killing the application, the app will never have a ready ad.
In this case, it’s preferred to use a loading screen (that might be used to load your assets) and only show the ad from the loading screen (Only if the ad is ready and the loading screen is still active) to avoid surprising the user with an ad while using your app.
If you have a loading screen under the app open ad, and your loading screen completes loading before the ad is dismissed, you may want to dismiss your loading screen in the resumeAfterAd() callback of the AppOpenPlacementListener.