Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, AdMob: AdMob ad refresh destroys frame rate

Tags:

android

admob

I am developing a game and it's coming along quite nicely. I do have a bit of a problem about the AdMob ad refreshing though. Every time the ad is refreshed or it draws a different aspect of the ad, my frame rate plummets and almost makes the game unplayable. Here is what I have for the loading of the ad...

    ad = new AdView(this, AdSize.BANNER, "...");

    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice("...");
    adRequest.addTestDevice("...");

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    ad.setLayoutParams(lp);

    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(renderView);
    layout.addView(ad);
    ad.loadAd(new AdRequest());     

    setContentView(layout);

My solution for rendering the ad on top of the SurfaceView was to just add it to a RelativeLayout and add both the SurfaceView and AdView to it. This all works fine and dandy, but every time the ad refreshes (UI or new Ad request), it bogs down the UI thread, which in turn slows down my render thread.

Is there a way that I can make all of this work together nicely to have all work done by the AdView done separately from the main thread? I am not too sure about dynamically updating the current layout from another thread.

Thanks for the help.

like image 983
SemperGumbee Avatar asked Feb 20 '12 18:02

SemperGumbee


1 Answers

I had this problem too. I found it was caused by Google ads which animate when they change, rather than static Admob banner ads which don't animate at all. There's a setting in your admob app settings for controlling whether Google ads are used... try turning it off to see if it makes a difference.

like image 103
Reuben Scratton Avatar answered Sep 19 '22 09:09

Reuben Scratton