The following sections show you how to load and then show and hide a banner or MREC ad.
Loading a Banner or MREC
To load a banner or MREC, create a MaxAdView object that corresponds to your ad unit.
Then call call that object’s loadAd() method.
To show that ad, add the MaxAdView object as a subview of your view hierarchy.
Implement MaxAdViewAdListener so that you are notified when your ad is ready (you will also be notified of other ad-related events).
If your integration requires displaying MREC ads in a content feed, AppLovin recommends the following:
Create the minimal amount of instances possible.
Stop auto-refresh.
Manually refresh the contents by calling loadAd() (re-use the MaxAdView instances).
You can find an example implementation in the AppLovin demo app (Java, Kotlin).
Loading and Showing a Banner or MREC in Layout Editor
Alternatively, you can add MAX banners or MRECs to your view layout XML.
Ensure that your ads are fully functional by setting a background or background color (android:background).
In the case of banners, stretch the width (android:layout_width) to the width of the screen.
In the case of MRECs, set android:adFormat accordingly:
If you no longer need a MaxAdView instance, call its destroy() method to free resources.
This may be the case, for example, if the user purchases ad removal.
Do not call the destroy() method if you use multiple instances with the same Ad Unit ID.
Adaptive banners are responsive banners with heights that derive from the device type and the width of the banner.
You integrate adaptive banners in a similar way to how you integrate regular banners.
However, you must set the height to the value returned by MAAdFormat.banner.adaptiveSize.height rather than to a constant like 50 or 90.
Before you load the ad, set the banner extra parameter adaptive_banner to true as shown in the code below:
For more specific integrations, you can set a custom width by using the local extra parameters API (as of Google adapter version 21.5.0.3 and Google Ad Manager adapter version 21.5.0.2).
You can fetch the appropriate height for your custom adaptive banner by using the adaptive size API.
Adaptive banners are anchored by default.
Alternatively, you can enable inline adaptive banners, which are meant to appear in scrolling content.
Inline adaptive banners are typically larger and taller than anchored adaptive banners.
They have variable heights that can extend to the full height of the device screen.
Inline adaptive banners are supported starting with Android adapter version 23.2.0.1 and iOS adapter version 11.7.0.1. To enable, set the extra local parameter adaptive_banner_type to inline, as shown in the code below:
You may want to set a maximum height, in dp, for your inline adaptive banners.
You can do this with code like the following, which uses a height of 100 dp as an example:
You may need to configure your UI in a way that depends on the adaptive banner size.
If so, you can retrieve the width and height of the loaded ad, in dp, with code like the following:
You may want to stop auto-refresh for an ad.
This may be the case when you hide an ad or when you want to manually refresh.
Stop auto-refresh with the following code: