简体   繁体   English

防止广告多次触发

[英]Prevent Ad from triggering multiple times

When I run this code on a real device the ad-banner pops up endless times. 当我在真实设备上运行此代码时,广告横幅会无休止地弹出。 How should i modifiy this code to run it just once? 我应该如何修改此代码以使其仅运行一次? This code is from a game. 该代码来自游戏。 Every time the player gets hit by something he loses 1 shield. 玩家每次被某物击中时都会失去1点护盾。

private void showBanner() {
    adView.setVisibility(View.VISIBLE);
    adView.loadAd(new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
}

if (player.getShieldStrength() == 0){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    showBanner();
                }
            });
        }

This my logcat: 这是我的日志:

Aborting last ad request since another ad request is already in progress.     
The current request object will still be cached for future refreshes.
...

This runnable is triggered by the run method. 此runnable由run方法触发。 showBanner is part of update-method showBanner是更新方法的一部分

@Override
    public void run() {
        while (playing) {
            update();
            draw();
            control(); }}

You are confused. 你很困惑。

A banner ad is not like an interstitial. 横幅广告是喜欢的间隙。 It does not pop-up. 它不会弹出。

When you request a banner ad you are requesting ads to fill that AdView until you tell it to stop or you hide it. 当您请求横幅广告时,您是在请求广告填充该AdView,直到您告诉它停止或隐藏它为止。 It will show new ads on the refresh cycle you have configured in the Admob dashboard. 它将在您在Admob信息中心中配置的刷新周期中展示新广告。 It will not show a single ad. 它不会显示一个广告。

If you really only want a banner ad to be shown until the next game, then call adView.setVisible(VIEW.INVISIBLE) or adView.setVisible(VIEW.GONE) 如果您确实只希望在下一场比赛之前展示横幅广告,请致电adView.setVisible(VIEW.INVISIBLE)adView.setVisible(VIEW.GONE)

And please don't repost existing questions Ad pops up multiple times 并且请不要重新发布现有问题广告会多次弹出

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

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