【发布时间】:2014-05-14 16:16:08
【问题描述】:
我完成了我的第一个应用程序,我想尝试在其中添加一些广告。 我尝试了谷歌提供的教程,它们工作正常。 现在,当我尝试在我的应用程序中实现添加时,我收到错误消息: “IllegalStateException: isLoaded 必须在主 UI 线程上调用”。
所以这是我在主活动中所做的,我有 onCreate 方法:
public void onCreate(){
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("xxxxxxxxxxxxxx")
.build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}
在我的同一个活动中:
public void showInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
因此,当我尝试调用 showInterstitial 方法时,我收到了上述错误。 我已经坐了几个小时了,找不到任何解决方案。
【问题讨论】:
标签: android ads interstitial