我是新手到Android,它的我AndroidLauncherjava文件intersial代碼上ADMOB-java.lang.IllegalStateException:isLoaded必須調用主UI線程
@Override public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MyGdxGame(this),config);
AdView adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-6916351754834612/9855033027");
adView.setAdSize(AdSize.BANNER);
adView.loadAd(new AdRequest.Builder()
.build());
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(adParams);
adView.setBackgroundColor(Color.BLACK);
layout.addView(adView, adParams);
iAd = new InterstitialAd(this);
iAd.setAdUnitId(AD_UNIT_ID);
loadInterstitial();
iAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
}
@Override
public void onAdFailedToLoad(int errorCode) {
}
});
setContentView(layout);
}
public void loadInterstitial() {
/*AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("0FD328B10106BD9B2BE832163D43D085")
.build();*/
AdRequest adRequest = new AdRequest.Builder().build();
iAd.loadAd(adRequest);
//iAd.loadAd(adRequest);
}
public void showInterstitial() {
if (iAd.isLoaded()) {
iAd.show();
} else {
//Log.d(TAG, "Interstitial ad is not loaded yet");
}
}
它我的插頁式廣告代碼;我得到java.lang.IllegalStateException: isLoaded must be called on the main UI thread
這裏.Checked幾個解決方案,可以不固定。我才知道的iAd是不是loading.Can任何人幫助我,我哪裏錯了。謝謝你在前進
我張貼我的解決方案在http://stackoverflow.com/questions/28501787/admob-interstitial-and-error-isloaded-must-be-called-on-the-main-ui-thread/34845549#34845549 – 2016-01-18 00:47:43