Adding a "dummy" AdController Interface

Before we go to adding Interstitial Ads let's first take care of the error notification in the file (located in the SRC folder of your desktop project). Your DesktopLauncher should look like this:

When we added the constructor to our game's main class (MyGdxGame in the Core project) we specified that an AdsController needs to be passed to it when we create a new MyGdxGame object. Here on line 8 when we create that new instance of MyGdxGame we're not passing anything to the constructor. We can take care of the error by passing a null argument to the constructor like this:

And then in the constructor of MyGdxGame I'll check whether the AdsController is passed (from the Android project) or a null argument is passed (from the Desktop project). When I run my project on my the Desktop I actually don't want to run the (Android related) code to display AdMob ads and I can do that by creating and referring to a DummyAdsController Interface instead of the AdsController.

Let me show you how to do that:

  • First change the constructor of the MyGdxGame class

  • Second: Add the DummyAdsController:

  • Because the DummyAdsController interface isn't created yet you'll get an error message from your IDE. In Eclipse if you left-click on the error message you can let Eclipse auto generate the class including it's methods for you. And that's it. You can now run your Desktop project without ads as well as your Android project with ads.

    In the next section: Interstitial Ads!