How to show interstitial Ad before launching new activity after click a button?

前端 未结 2 1117
小蘑菇
小蘑菇 2021-02-04 18:49

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

2条回答
  •  失恋的感觉
    2021-02-04 19:16

    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

提交回复
热议问题