簡體   English   中英

每 90 秒加載一次時,InterstitialAds 未在活動中加載

[英]InterstitialAds are not loading in activity while loading every 90 seconds

private final String TAG = "RedFM_AdsDemoActivity";
    private InterstitialAd interstitialListen;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ads_demo);
    MobileAds.initialize(this, getString(R.string.google_ad_app_id));
    // Create the InterstitialAd and set the adUnitId.
    interstitialListen = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialListen.setAdUnitId(getString(R.string.admob_interstitial_id_google));
    interstitialListen.loadAd(new AdRequest.Builder().build());
    interstitialListen.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {              
            loadInterstitial();
        }
    });
    resumeGame(20000);
}

private static final long GAME_LENGTH_MILLISECONDS = 20000;
public CountDownTimer countDownTimer;
public boolean gameIsInProgress;

public void createTimer(final long milliseconds) {
    // Create the game timer, which counts down to the end of the level
    // and shows the "retry" button.
    if (countDownTimer != null) {
        countDownTimer.cancel();
    }
    countDownTimer = new CountDownTimer(milliseconds, 1000) {
        @Override
        public void onTick(long millisUnitFinished) {

        }

        @Override
        public void onFinish() {
            gameIsInProgress = false;
            showInterstitial();
        }
    };
}

public void showInterstitial() {
    // Show the ad if it's ready. Otherwise toast and restart the game.
    if (interstitialListen != null && interstitialListen.isLoaded()) {
        interstitialListen.show();         
    } else {
        loadInterstitial();
    }
}

public void loadInterstitial() {
    // Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
    if (!interstitialListen.isLoading() && !interstitialListen.isLoaded()) {
        System.out.println(TAG + "Listen  ads loaded");
        AdRequest adRequest = new AdRequest.Builder().build();
        interstitialListen.loadAd(adRequest);
    } else
        System.out.println(TAG + "Listen  ads not loaded");
    resumeGame(GAME_LENGTH_MILLISECONDS);
}

public void resumeGame(long milliseconds) {
    // Create a new timer for the correct length and start it.
    System.out.println(TAG + "Listen  resumeGame called ");
    gameIsInProgress = true;
    createTimer(milliseconds);
    countDownTimer.start();
}

@Override
protected void onPause() {
    super.onPause();
    if (countDownTimer != null)
        countDownTimer.cancel();
}

**1.當我將 ListenActivity 移動到 MainActivity 時,那時兩個 Activity 都會加載廣告。

但是,當我將 MainActivity 移動到 ListenActivity 時,此時廣告顯示在 MainActivity 上,但廣告未加載到 ListenActivity 上。我收到“廣告無法加載:0”的消息,請幫助我在來自 MainActivity 的同時在 ListenActivity 上顯示廣告。**

使用Test Ad Idsdebug應用中顯示廣告。 Ad-mobSDK不會在debug模式下顯示ads或制作發布APK然后廣告會顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM