I've recently started learning Java for android development. My first game is almost ready to publish in Google Play, but I'm affraid that google might say that on the one screen, the ad may be clicked accidentally, So I would like to hide it on that screen. The thing is, that Adview is initiated only in AndroidLuncher class in android project, but all the other classes are in core project. So what I'm asking for is a way to instruct Admob to hide when player enters GameScreen. Is that possible?

I could provide some code, but I don't know which part could help you, so I'll just post the AndroidLauncher Class onCreate method:

protected void onCreate (Bundle savedInstanceState) {

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.useAccelerometer = false;
    config.useCompass = false;

    RelativeLayout layout = new RelativeLayout(this);


    // Create the libgdx View
    View gameView = initializeForView(new MainClass(), config);

    AdView AdView = new AdView(this);
    AdView.setAdUnitId("ca-app-pub-SECRETCODE/HERE"); //The AdUnitId
    AdRequest.Builder adRequest = new AdRequest.Builder();
    adRequest.addTestDevice("HERE_TOO"); //Test device


    // Add the AdMob view
    RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 

    layout.addView(AdView, adParams);

    // Hook it all up


This code works just fine, so I would prefer not to change it, as I've spent many hours getting it to work :)


1 Answer 1


If you ask me it is not a good approach. Good news is you don't have to change too much stuff. Create an ads controller interface in your core module and implement it in your main Android class. So you can pass it to your game class and store it. Then whenever you want you can call adsController.hideBannerAd(); But you should first implement that method :D

EDIT tutorial for how to do it: http://www.norakomi.com/tutorial_admob_introduction.php#scroll_introduction

  • \$\begingroup\$ Okay, so I tried with this: github.com/libgdx/libgdx/wiki/Admob-in-libgdx#control but when I try using "myRequestHandler.showAds(false);", it doesn't work :/ \$\endgroup\$
    – urban07
    Aug 18, 2015 at 12:05
  • \$\begingroup\$ I've also tried an infinite loop inside AndroidLauncher.java that checks a variable in main core class, but it doesn't work either. I'll try running a seperate thread for this goal. \$\endgroup\$
    – urban07
    Aug 18, 2015 at 12:36
  • \$\begingroup\$ @urban07 you don't need a separate thread I will provide you a link which explains what you should do. \$\endgroup\$
    – Arda Kara
    Aug 18, 2015 at 14:25
  • \$\begingroup\$ Okay, nvm - this article helped me a lot: norakomi.com/tutorial_admob_part2_banner_ads2.php I guess this is what you meant :) EDIT: woah, this is basically the same link :D Thanks for giving me a hint! \$\endgroup\$
    – urban07
    Aug 18, 2015 at 14:27
  • \$\begingroup\$ Hope you finish your game 👍 \$\endgroup\$
    – Arda Kara
    Aug 18, 2015 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .