libGDX, AdMob, and Google Play Leaderboards

Hi, I’m developing an app using libGDX and have some trouble integrating AdMob and Leaderboards. Lets start with AdMob.

I followed the AdMob tutorial in the libGDX wiki, but have a couple problems. I set my ads to display only when playing, so I have a class called “GameScreen” that shows and loads the ads when instantiated. That way ads don’t clutter the title screen or any other screen. The first problem is that ads don’t load immediately when GameScreen is loaded. LogCat says the ad finished loading, but it doesn’t display (and the AdView’s visibility is View.VISIBLE). Only when the next refresh occurs (in thirty seconds) do they start to show.

The second problem happens with ads not refreshing. Staying on the GameScreen playing the game will never interrupt the refresh cycle, but leaving the GameScreen does. When GameScreen exits, it sets the AdView’s visibility to View.GONE. Staying in the title screen longer than the time until the next ad refresh causes the cycle to go bork. LogCat prints out “Ad is not visible. Not Refreshing ad.” and schedules an ad refresh in sixty seconds (not sure why it’s not thirty seconds). When you return to the GameScreen, an ad loads and doesn’t refresh. Returning to the title screen and going back to the GameScreen does load a new ad, but it doesn’t refresh automatically after thirty seconds while playing. The same ad will show until the player exists the GameScreen.

Here’s the code for my MainActivity: Clicky!
And here’s the code for my Ad Handler: Clicky!

GameScreen calls SHOW_ADS and LOAD_ADS when created, and HIDE_ADS when it exits.

------------------------

Now for leaderboards. I read the tutorial on the libGDX wiki, but it doesn’t go into much detail and only talks about updating scores and achievements. I want to send the scores to a leaderboard I created in my Google Play dashboard and show the leaderboards when I press a button in-game. How do I change the view to the leaderboards view, and send scores to it?

Let me know if you need any more details. Any help would be appreciated for either of my two problems! :smiley:

Here’s the fix for your first problem. Don’t ask me why, this just works


adView.setBackgroundColor(Color.TRANSPARENT);
adView.loadAd(request);

That should load your ad immediately.

As for your other probleme, I’m not sure. Maybe start a new AdRequest or something?

Thanks, your solution worked! :smiley: Ads now immediately display.

I can call an ad request, but it won’t restart the cycle. To put it simply, if I request an ad when one is already scheduled to refresh, it interrupts the cycle. Does anyone know how to restart it?

I managed to fix ads not refreshing by simply not re-loading the ads when the GameScreen is re-entered. I only call LOAD_ADS the first time GameScreen is loaded, and then only hide/show the ads when leaving/entering GameScreen.

But I still have no idea how to implement Google Play Leaderboards into my game with libGDX. Has anyone done this before and can show me how to do it? Thanks in advance! :smiley:

Your welcome in advance! 8)

Well saucymeatman sir. I guess you just nominated yourself to implement leaderboards in my game. :stuck_out_tongue: Chop chop, write the code.