Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

android - Admob ads appear only after first refresh

i added banner ads from admob to my game and the banner add appears only after the first refresh (30 seconds) . And for the first 30 seconds it's there and if you click the bottom of the page where the addvertisment should be it takes you to the advertising page but the ad is not visible.

You can see for yourself when you start the game and click bottom of the screen. Game #1

And my other game (if you start the intent from the menu in this game ( like facebook) and then return to the menu, ads appear instantly): Game #2

Anyone had this happen ? What can i do to fix this ?

How I initialize my ads :

    @Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RelativeLayout layout = new RelativeLayout(this);

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    opener = new AndroidGalleryOpener(this);
     requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    View gameView = initializeForView(new Zaidimas(opener), config);
    AdView adView = new AdView(this);
    adView.setAdUnitId("xxxxx my secret number xxxxxxxx");
    adView.setAdSize(AdSize.BANNER);
    adView.loadAd(new AdRequest.Builder()
    .build());
    layout.addView(gameView);
    RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        layout.addView(adView, adParams);
        setContentView(layout);
//initialize(new Zaidimas(opener), config);

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is hard to say what happens in your case, but I have a suspect that your libgdx screen with the admob banner might show up before the ad finished loading. You can try adding an AdListener that forces the ad-view to draw itself once the ad finished loading. Something like:

    adView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            System.out.println("ad banner finished loading!");
            adView.setVisibility(View.GONE);
            adView.setVisibility(View.VISIBLE);
        }        
    });

The code looks a bit odd, but changing visibility should really make sure that your adView gets drawn again ;-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...