Interstitial Ads
Overview
Before You Start. Make sure that you have correctly integrated the BlueStack SDK into your application. Integration is outlined here.
For a working implementation of this ad format, see the azerion-inapp-demo-android demo app.
Create an Interstitial Ad
To create an interstitial you must init an object with type InterstitialAd :
- Java
- Kotlin
InterstitialAd interstitialAd = new InterstitialAd(activity, "INTERSTITIAL_PLACEMENT_ID");
val interstitialAd = InterstitialAd(activity, "INTERSTITIAL_PLACEMENT_ID")
Load an Interstitial Ad
Note: Make all calls to the BlueStack SDK on the main thread.
With RequestOptions
To request an interstitial ad using RequestOptions, provide an instance of RequestOptions in the InterstitialAd's load method:
- Java
- Kotlin
interstitialAd.load(requestOptions);
interstitialAd.load(requestOptions)
Without RequestOptions
- Java
- Kotlin
interstitialAd.load()
interstitialAd.load()
Note:
-
To avoid stacking up two interstitial Ad BlueStack added lock system :
- InterstitialAd will ignore any interstitial request while there is a pending request or there is interstitial shown at that moment.
Ad events
Register for Interstitial events
To recieve ad's lifecycle events regisger a listerner in InterstitialAd.
- Java
- Kotlin
// set intertitial listener
public class InterstitialFragment extends Fragment implements InterstitialAdListener {
...
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
interstitialAd.setInterstitialAdListener(this);
...
}
...
}
// set intertitial listener
class InterstitialFragment : Fragment(),
InterstitialAdListener {
...
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
...
interstitialAd.setInterstitialAdListener(this)
...
}
...
}
Implement Interstitial events
The SDK will notify your Listener of all possible events listed below :
- onAdLoaded(): will be called by the SDK when your Interstitial is ready.
- Java
- Kotlin
@Override
public void onAdLoaded() {
Log.d(TAG, "interstitial did load");
}
override fun onAdLoaded() {
Log.d(TAG, "interstitial did load")
}
- onAdFailedToLoad(Exception adsException): will be called when all ads servers fail. it will return the error of last called ads server.
- Java
- Kotlin
@Override
public void onAdFailedToLoad(Exception adsException) {
Log.e(TAG, "interstitial did fail :" + adsException.toString());
}
override fun onAdFailedToLoad(adsException: Exception) {
Log.e(TAG, "interstitial did fail :" + adsException.toString())
}
- onAdDisplayed(): will be called when interstitial was shown.
- Java
- Kotlin
@Override
public void onAdDisplayed() {
Log.d(TAG, "interstitial Did Shown");
}
override fun onAdDisplayed() {
Log.d(TAG, "interstitial Did Shown")
}
- onAdFailedToDisplay(@NonNull Exception exception): will be called when interstitial is failed to display.
- Java
- Kotlin
@Override
public void onAdFailedToDisplay(@NonNull Exception exception) {
Log.e(TAG, "interstitial did fail :" + adsException.toString());
}
override fun onAdFailedToDisplay(@NonNull Exception exception)p pbgh {
Log.e(TAG, "interstitial did fail :" + adsException.toString());
}
- onAdClicked(): will be called when user click the Interstitial ad.
- Java
- Kotlin
@Override
public void onAdClicked() {
Log.d(TAG, "Ad Clicked");
}
override fun onAdClicked() {
Log.d(TAG, "Ad Clicked")
}
- onAdDismissed(): will be called when interstitial was dismissed.
- Java
- Kotlin
@Override
public void onAdDismissed() {
Log.d(TAG, "interstitial disappear");
}
override fun onAdDismissed() {
Log.d(TAG, "interstitial disappear")
}
Show an Interstitial Ad
To check if the interstitial is ready to be shown, you must call isReady() and show() in order to display the ad (in case of success) :
- Java
- Kotlin
...
if (interstitialAd.isReady()) {
interstitialAd.show();
} else {
Log.d(TAG, "Interstitial not ready ");
}
...
...
if (interstitialAd.isReady()) {
interstitialAd.show()
} else {
Log.d(TAG, "Interstitial not ready")
}
...
Destroying Interstitial Ad
When you have finished your ads plant you must free the memory.
- Java
- Kotlin
@Override
protected void onDestroy() {
if (interstitialAd != null) {
interstitialAd.destroy();
interstitialAd = null;
}
super.onDestroy();
}
override fun onDestroy() {
interstitialAd?.destroy()
interstitialAd = null
super.onDestroy()
}