libgdx android : Admob adrequest occasionally prevents my game form starting

Hi Guys,

I’ve created a game that uses AdMob to show interstitial ads between screenswitches.
When my app starts up it first shows my logosplash screen -> then switches screen and show an app (when there is an internet connection and if not) -> then switches screen to show my games Title screen.

Now when i turn off the wifi connection on my android device it all works perfect.
I’ve added this method to my AndroidLauncher to check for network connection:

	@Override
	public boolean isNetworkConnected() {

		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = cm.getActiveNetworkInfo();
		if (ni == null) {
			// There are no active networks.
			return false;
		} else
			return true;
	}

which gets called from within my logoSplashScreen class to check if my device is connected to the Network and either display the interstitial ad or not, with this piece of code:

if (switchScreen) {

			if (game.getAdsController().isNetworkConnected() == true) {

				game.getAdsController().showInterstitialAd(new Runnable() {
					@Override
					public void run() {

						game.setScreen(game.titleScreen);
					}
				});

			} else {
				game.setScreen(game.titleScreen);
			}
		}

Now what happens is that (too) occasionally my app freezes up when there IS a network connection at the time my logo faded out and it needs to switch from the logoSplashScreen to show the Interstitial ad.

I’m not sure what’s going wrong and how to solve this.
Anyone experience with this?

I found something that night do the trick:


		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = cm.getActiveNetworkInfo();
	
		if (ni == null) {
			// There are no active networks.
			return false;
		} else
			if (ni.isConnected() == true) {
				return true;
			} else {
				return false;
			}
		
	}

I’ve added an isConnected() check which will check whether network connectivity exists and it is possible to establish connections and pass data.
Not 100% sure yet because i have to run the game a couple of times, but it’s looking good so far.

  • Edit: No this is not it, still ran into a “freeze”