My Libgdx Game Is Slow When Admob Is Integrated

I am a new game developing with libgdx. I have a problem with Admob ads. When I call adView.loadAd (adRequest); my game is slow when I start the game, FPS ~ 60, when I call adView.loadAd (adRequest), my game is slow FPS ~ 30.

Here is my

public class MainActivity extends AndroidApplication implements IActivityRequestHandler {

   protected AdView adView;
   AdRequest adRequest;
   private final int SHOW_ADS = 1;
   private final int HIDE_ADS = 0;

   protected Handler handler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
         switch (msg.what) {
         case SHOW_ADS: {
            System.out.println("SHOW ADVIEW");
            adView.setVisibility(View.VISIBLE);
            break;
         }
         case HIDE_ADS: {
            adView.setVisibility(View.GONE);
            break;
         }
         }
      }
   };

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

      // Create the layout
      RelativeLayout layout = new RelativeLayout(this);

      // Do the stuff that initialize() would do for you
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

      // Create the libgdx View
      View gameView = initializeForView(new MyGdxGame(this), false);

      // Create and setup the AdMob view`enter code here`
      adView = new AdView(this, AdSize.BANNER, "XXXXXX"); // Put in your
                                                // secret key
                                                // here
      adRequest = new AdRequest();
      adView.loadAd(adRequest);
      // adView.loadAd(new AdRequest());

      // Add the libgdx view
      layout.addView(gameView);

      // Add the AdMob view
      RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
      adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
      adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

      layout.addView(adView, adParams);

      // Hook it all up
      setContentView(layout);
   }

   // This is the callback that posts a message for the handler
   @Override
   public void showAds(boolean show) {
      handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
   }
}

I read the topic Using interstitial ads from Admob in the game Libgdx for Android, it’s slow when it is rejected
but not a solution. Please help me if you have a solution.

+3
source share
1 answer

This is a known issue and you cannot change it at this time.

Forum post libgdx

There is nothing to do with your code. I think,

+1
source

All Articles