I am loading banner ads and interstitial ads at different events. The problem is ads are loading fine at some places and at some place, they are not loading at all. I used same method to load the ads all over the application so why are they not loading at some points? Here is the code to interstitial ads which is working fine in splash screen :
setContentView(R.layout.splash);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.AdUnitId_interstitial));
requestNewInterstitial();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
}
finish();
}
}, SPLASH_TIME_OUT);
}
The same code is not working in drawer activity. Here is the code in onCreate
:
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.AdUnitId_interstitial));
requestNewInterstitial();
Here is the code for the button click handler:
else if (id == R.id.audio) {
startActivity(new Intent(MainActivity.this, AndroidBuildingMusicPlayerActivity.class));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
}
And for banner ads i am using this :
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest1 = new AdRequest.Builder().build();
mAdView.loadAd(adRequest1);
It works fine in a few activities and doesn't work in some. Anyone got a clue?