点击按钮后,如何在启动新活动之前显示插页式广告? [英] How to show interstitial Ad before launching new activity after click a button?

查看:55
本文介绍了点击按钮后,如何在启动新活动之前显示插页式广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用选项菜单按钮转到第二个活动.当用户在启动第二个活动后点击该菜单按钮时,插页式广告就会显示.但是我想在启动第二项活动之前显示插页广告,并且当用户单击插页广告的关闭按钮时,第二项活动应该启动.

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;

推荐答案

也许是这样的?使用 onAdClosed 函数开始活动

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");
        } 
 });

在此处阅读有关此内容的更多信息: https://developers.google.com/admob/android/interstitial

Read more about this here: https://developers.google.com/admob/android/interstitial

这篇关于点击按钮后,如何在启动新活动之前显示插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆