I use option menu button to go to second activity. When user click on that menu button interstitial Ad show after launching second activity. But I want to show interstitial Ad before launching second activity and when user click on close button of interstitial Ad, second activity should launch.
I'm using the code below to show interstitial Ad.
case R.id.button_id:
startActivity(new Intent(this, secondactivity.class ));
interstitial = new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId(getString(R.string.admob_interstetial_ad));
AdRequest adRequest9 = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
interstitial.loadAd(adRequest9);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
return true;
Maybe something Like this? Use the onAdClosed
function to start activity
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
@Override
public void onAdClosed() {
startActivity(new Intent(this, secondactivity.class ));
// Code to be executed when when the interstitial ad is closed.
Log.i("Ads", "onAdClosed");
}
});
Read more about this here: https://developers.google.com/admob/android/interstitial