Reputation: 121
I'm trying to understand why onAdClosed() doesn't get called after a user closes an ad?
I'll trying to create a new InterstitialAd to load and display later using the display method.
Any advice would be great, thanks guys.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox_list);
createAdmobBanner();
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-xxxxx/xxx");
// Create ad request.
AdRequest adRequestIN = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequestIN);
// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial()
{
if (interstitial.isLoaded())
{
interstitial.show();
Log.d("response", "AD IS LOADED: ");
}
else
{
Log.d("response", "AD IS NOT LOADED: " );
}
}
public void onAdClosed()
{
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-xxxxx/xxxx");
// Create ad request.
AdRequest adRequestIN = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequestIN);
Log.d("response", "onAdClosed: " );
}
Upvotes: 4
Views: 3465
Reputation: 141
In this version in your gradle.file
implementation 'com.google.android.gms:play-services-ads:21.5.0'
in your Activity.java just load Interstitial Ad in onCreate function
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadInterstitialAd();
...
}
after implementation your loadInterstitialAd(); method paste this code when you show your ads
public void displayInterstitial()
{
if (mInterstitialAd != null) {
mInterstitialAd.show(this);
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent();
startActivity();
}
});
} else {
startActivity();
}
}
Upvotes: 0
Reputation: 121
It required an AdListener.
// Set an AdListener.
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Toast.makeText(MyActivity.this,
"The interstitial is loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed() {
// Proceed to the next level.
goToNextLevel();
}
});
Useless link for beginners:(Not Working) https://developers.google.com/android/reference/com/google/android/gms/ads/InterstitialAd
Upvotes: 2
Reputation: 13761
There's a misunderstanding on what you understand as closing and what Android
defines as closing an Ad. What you mean is called dismissing the ad, while for Android, closing the Ad, as referenced by the documentation is:
Called when the user is about to return to the application after clicking on an ad.
You can find more info here.
Upvotes: 0