Ad pops up multiple times

2019-08-12 16:50发布

If the player shield gets below 0 the game ends and an ad should pop up once and stay till the next game is started but it pops up twice. I cant find my mistake.

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

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

My showBanner Method:

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

0条回答
登录 后发表回答