Interstitial AdMob 在关闭后打开

Interstitial AdMob opens after closing

我已经使用 Interstitial AdMob 创建了一个应用程序,但是,当它打开广告并关闭它时,它会再次打开等等...我想要做的是在应用程序启动 5 次后投放广告.这是我的代码。

    sharedPreferences = getPreferences(0);
    int count = sharedPreferences.getInt("numRun", 0);
    count++;
    sharedPreferences.edit().putInt("numRun", count).commit();

    MobileAds.initialize(this, "ADMOB_ID");
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.INTERSTITIAL_ID));

    mInterstitialAd.loadAd(new AdRequest.Builder().build());

    mInterstitialAd.setAdListener(new AdListener(){
        @Override
        public void onAdLoaded() {
            int count = sharedPreferences.getInt("numRun", 0);

            if (count == INTERSTITIAL_LAUNCH) {
                count = 0;
                sharedPreferences.edit().putInt("numRun", count).commit();
                mInterstitialAd.show();
            }
        }
        @Override
        public void onAdClosed() {
            // Code to be executed when the interstitial ad is closed.
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
        }
    });

其中 INTERSTITIAL_LAUNCH 是 4 的整数。

你说 INTERSTITIAL_LAUNCH 是 4 的整数。

当您根据此值检查变量 count 时,根据代码,如果其值大于 4,则广告也会显示。

将其替换为:

if (count == 5)