Issue
I want to display AdMob interstitial ad on exit link from the nav bar and close the app on click of either on the interstitial ad or the close button of the ad.
I am using the following codes but it won't work:
InterstitialAd mInterstitialAd;
void loadAdsFullScreen(){
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad));
AdRequest request = new AdRequest.Builder()
.tagForChildDirectedTreatment(true)
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(request);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial1();
}
});
}
The code I am using for closing the app and showing the ads is:
else if (id == R.id.nav_exit) {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad));
AdRequest request = new AdRequest.Builder()
.tagForChildDirectedTreatment(true)
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(request);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
finish();
}
});
Test1.this.finish();
System.exit(0);
}
Solution
Override onAdClosed of listener like,
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
@Override
public void onAdClosed() {
Activity_Class_Name.this.finish();
}
@Override
public void onAdOpened() {
Activity_Class_Name.this.finish();
}
});
Answered By - Exigente05
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.