How to disable admob in libgdx

I added admob to my libgdx project without any problem but How can I disable admob in game. I have 2 screen(MainMenu and PlayScreen) and I want to ads to be shown only at MainMenu.

I have found an article about conntrolling ads in libgdx but the problem is this article is for Desktop not Android. (Note: question arises in part from using deprecated document, newer version available at


Take a look at the #control at the new wiki. There are 2 Final static values inside of your Android Project:

public class HelloWorldAndroid extends AndroidApplication {

private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;

protected Handler handler = new Handler()
    public void handleMessage(Message msg) {
        switch(msg.what) {
            case SHOW_ADS:
                adView.setVisibility(View.VISIBLE); //change to visible
            case HIDE_ADS:
                adView.setVisibility(View.GONE);//change to not visible
                // you should also disable the ad fetching here!

So if you call the method: (which is parsed as interface to the core project)

public interface IActivityRequestHandler {
   public void showAds(boolean show);

public class HelloWorldAndroid extends AndroidApplication implements IActivityRequestHandler  {


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

it sends an message to the handler which activates or disable the admob. The interface for showAds is passed to the core project so you can hold an reference to it and use it. To see how this works take a look at the article of interfacing plattformspec code.

Just to show this here:

View gameView = initializeForView(new HelloWorld(this), false); // and "this" is the mainclass of the android project which implements the IActivityRequestHandler interface shown above
//the HelloWorld(this) is the core project where you now can save the `IActivityRequestHandler` as referance and call the showAds(bool)

But in the end if you would have read the aticle you should have know this all.

Need Your Help

how to periodically run sql query in azure?

sql azure azure-sql-database

I know some jobs can be run periodically or querys a database. how achievement run this code every "x" days in an azure sql table?

NullPointerException in handleStopActivity -- No reference to my code in stack trace

java android

I'm a bit at a loss, here. I've been seeing a steadily increasing number of these NullPointerExceptions in handleStopActivity. I suspect that the increase coinicides with the increase in 2.2 upgrad...