android - 如何在点击后、新 Intent 之前加载插页式广告?

标签 android android-intent admob interstitial

我的主页有大约 10 个按钮,每个按钮都会加载一个新 Intent 。

@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        }

        switch(v.getId())
        {
            case R.id.troop_button:
                gotoTroopScreen();
                break;
        }
    }


public void gotoTroopScreen()
{
    Intent intent = new Intent(this, troop.class);
    startActivity(intent);
}

我希望用户单击按钮,查看插页式广告,然后查看部队屏幕。现在,它首先加载部队屏幕,然后在用户退出部队屏幕后显示插页式广告。有没有办法让插屏先显示?

最佳答案

onCreate 中加载您的添加,如下所示

 interstitial = new InterstitialAd(this);   
 interstitial.setAdUnitId("YOUR_AD_UNIT_IT");

 AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();

 interstitial.loadAd(adRequest);

然后单击按钮,调用以下函数:

 public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
 }

当用户关闭广告时,转到下一个 Activity :

// Set an AdListener.
 mInterstitialAd.setAdListener(new AdListener() {
             @Override
             public void onAdLoaded() {
                 //Here set a flag to know that your 
             }

             @Override
             public void onAdClosed() {
                 // Proceed to the next activity.
                 goToNextActivity();
             }
         });

注意:用户有可能在插页式广告加载之前点击按钮。

关于android - 如何在点击后、新 Intent 之前加载插页式广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29887671/

相关文章:

android - Android 4.0.3 上的 Keystore 版本错误

java - 共享 viewpager 制作的 slider 中的特定图像

android - 如何在应用程序加载一定时间后加载 Admob 广告?

android - Google Play 服务与 AdMob。检查可用性?

安卓安全存储

android - React Native 多行 TextInput,文本居中

android - React-Native 中的线性渐变

Android 分享 Intent Twitter : How to share only by Tweet or Direct Message?

android - 我的应用程序不会运行,也不会切换 Activity

java - Google Play 服务上的广告声明在 APK 中显示 Admob