简体   繁体   English

AdMob插页式广告在恢复后重复加载

[英]AdMob Interstitial Ads Loading Repeatedly onResume

I want to load AdMob interstitial ads when the users opens the app and resumes the app after minimizing the app. 我想在用户打开应用并在最小化应用后恢复应用时加载AdMob插页式广告。

I am using the following code to load AdMob interstitial ads onResume : 我正在使用以下代码在onResume上加载AdMob插页式广告:

@Override
protected void onResume() {
    super.onResume();
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad));
    AdRequest request = new AdRequest.Builder()
            .tagForChildDirectedTreatment(true)
            .build();
    mInterstitialAd.loadAd(request);

mInterstitialAd.setAdListener(new AdListener() {
    public void onAdLoaded() {
        showInterstitial();
    }
});
}

But the ads keep loading repeatedly after closing. 但是,广告在关闭后会不断重复加载。 I tried to limit ads display once in 5 minutes in AdMob settings but it didn't work. 我试图限制广告在AdMob设置中每5分钟显示一次,但是没有用。 How do I prevent ads from loading repeatedly? 如何防止广告重复加载?

I want to load AdMob interstitial ads when the users opens the app and resumes the app after minimizing the app. 我想在用户打开应用并在最小化应用后恢复应用时加载AdMob插页式广告。

This is prohibited as per interstitial best practices: https://support.google.com/admob/answer/6201362?hl=en&ref_topic=2745287 . 根据插页式最佳做法,这是禁止的: https : //support.google.com/admob/answer/6201362?hl=zh_CN&ref_topic=2745287

Your code creates a circuit. 您的代码创建了一个电路。 You are loading the interstitial on the activity's onResume() , and showing it when onAdLoaded() is fired. 您正在将插页式广告加载到活动的onResume() ,并在onAdLoaded()时显示插页式广告。 However, for onAdLoaded() is fired, the interstitial must have been visibly displayed from before. 但是,如果onAdLoaded() ,则必须从之前就已经明显显示插页式广告。 So, since the interstitial is still around, it will dispatch onAdLoaded() , which shows the interstitial ( showInterstitial() ), which will dispatch another onAdLoaded() , which will call showInterstitial() again and again. 因此,由于插页式广告仍然存在,因此它将分派onAdLoaded()并显示插页式广告( showInterstitial() ),后者将分派另一个onAdLoaded() ,并再次调用showInterstitial()

You need to send the ad request early, and utilize the isLoaded() check before calling showInterstitial() . 您需要提早发送广告请求,并在调用showInterstitial()之前利用isLoaded()检查。

Send the ad request on app launch: 在应用启动时发送广告请求:

// Initialize the Mobile Ads SDK.
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

// Create the InterstitialAd and set the adUnitId.
mInterstitialAd = new InterstitialAd(this);

// Defined in res/values/strings.xml
mInterstitialAd.setAdUnitId(getString(R.string.ad_unit_id));

if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
        AdRequest adRequest = new AdRequest.Builder().build();
        mInterstitialAd.loadAd(adRequest);
}

Then, put this in your showInterstitial() : 然后,将其放入showInterstitial()

if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
}

EDIT : Only call showInterstitial() at a logical breakpoint in your app. 编辑 :仅在应用程序中的逻辑断点处调用showInterstitial() Showing interstitial ads on app launches or app exits does not comply with AdMob's interstitial best practices. 在应用启动或退出时显示插页式广告不符合AdMob的插页式最佳做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM