Advertisement Admob appears only once

Asked

Viewed 128 times

0

Hello, can someone help me with this problem? When I run my app on the emulator, the ad appears normally at all times, but when I run it on my mobile the ad appeared only once and did not appear again. What can that be? I’m using the Gdx library for my game

Class Android Launcher

public class AndroidLauncher extends AndroidApplication implements AdHandler {

    private static final String TAG = "AndroidLauncher";
    private final int SHOW_ADS = 1;
    private final int HIDE_ADS = 0;
    protected AdView adView;

    Handler handler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case SHOW_ADS:
                    adView.setVisibility(View.VISIBLE);
                    break;
                case HIDE_ADS:
                    adView.setVisibility(View.GONE);
                    break;
            }
        }
    };

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RelativeLayout layout = new RelativeLayout(this);

        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        View gameView = initializeForView(new BolsoBird(this), config);
        layout.addView(gameView);

        adView = new AdView(this);

        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                int visibility  = adView.getVisibility();
                adView.setVisibility(AdView.GONE);
                adView.setVisibility(visibility);
                Log.i(TAG,"Ad loaded...");
            }
        });
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId("xxxxxxx");

        AdRequest.Builder builder = new AdRequest.Builder();
        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );

        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

        layout.addView(adView, adParams);

        adView.loadAd(builder.build());
        setContentView(layout);
    }

    @Override
    public void showAds(boolean show) {
        handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
    }
}

I’m initiating the ad in the create method, of my game..

public void create () {
         .....
         .....
        handler.showAds(toggle); //toggle é sempre true..

    }
  • It showed up on my phone again for a while, but it doesn’t show up anymore, is it some kind of "block"? I tested it on my mom’s cell phone and my friend’s cell phone, and the ad’s coming up...

  • 1

    try to put the call to your showAds(...); in a method onResume

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.