I am currently including AdMob into some of my apps but am facing an issue. I try to display an interstitial when changing the activity as this would be the place where it wouldn't annoy users.
My initial understanding was, that displaying the Ad would put the activity into pause mode and resume it after the ad has been closed.
This assumption seems to be wrong, as with the below code, the activity gets switched directly, the toast is showing that an Ad should be displayed, but as long as I don't comment the startActivity(intent), I never see the ad.
I am loading the ad in onCreate, then try to display it in another void which is being triggered when a button has been clicked (and, of course, if it has finished loading by that point in time).
Sourcecode:
@Override
public void onCreate(Bundle SafedInstanceState)
{
[...]
LoadAd();
[...]
}
public void ShowAd(){
if (interstitial.isLoaded()) {
interstitial.show();
}
}
public void LoadAd(){
String MY_AD_UNIT_ID=getResources().getString(R.string.AdID);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}
public void SWITCHACTIVITY (View view) {
ShowAd();
Intent intent = new Intent (this, ANOTHERACTIVITY.class);
startActivity(intent);
finish();
}
Highly appreciate any input on what I'm doing wrong here or how I could achieve that the Ad gets displayed and the activity gets switched / closed AFTER the ad has been closed.
Thanks in advance!