简体   繁体   中英

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.

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. showBanner is part of update-method

@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. It will show new ads on the refresh cycle you have configured in the Admob dashboard. 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)

And please don't repost existing questions Ad pops up multiple times

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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