I did some testing with ads on my device and then pushed app to the play with with production unit ID. After a while when the version was available on play I deleted the debug build from my device and installed from playstore .
The code is same as what developer site suggests
mInterstitialAd = new InterstitialAd(callerActivity);
mInterstitialAd.setAdUnitId(callerActivity.getString(R.string.interstitial_ad_unit_id));
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
if (mInterstitialAd.isLoaded()) {
Log.i(TAG," Interstitial Add :Loaded");
mInterstitialAd.show();
}
else {
Log.i(TAG,"Could not load Interstitial Add");
}
But surprisingly I see following in logs
2:38.743 16617-16617/com.osfg.tictactoe I/Ads﹕ Starting ad request. 06-17 18:22:38.743 16617-16617/com.osfg.tictactoe I/Ads﹕ Use AdRequest.Builder.addTestDevice("235F7FAA8F49FF2CAA1DD2FAFE6B9E8A") to get test ads on this device. 06-17 18:22:40.529 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Game Over. Some player won 06-17 18:22:43.551 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Could not load Interstitial Add 06-17 18:22:43.551 16617-16617/com.osfg.tictactoe I/GamePlayOnClickListener﹕ Resetting game
It is still using my device as test device? Not sure what is happening here. Anyone has any prior experience on this? I know it calculates the hash but does it store it on admob server but again this is client call. How would it know? I am confused. Any suggestion is appreciated.
Most likely you're encountering this issue because
mInterstitialAd.loadAd(adRequest);
is calling a background thread to load a new ad, but you're checking to see if the ad has been loaded immediately. You don't give that background thread a chance to connect to the server, get the ad, etc.To fix this, you need to place your code for when the ad has been loaded inside an
AdListener
, like so:The if statement
if (mInterstitialAd.isLoaded())
is for checking at a later time if the ad has been loaded, such as after the user does some action. Not when an activity begins or anything similar.