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

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

问题描述

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

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天全站免登陆