我试图将非页内广告整合到初始屏幕活动中 通过使用此tutorial ..但广告未加载。
谁能告诉我问题出在哪里?
预先感谢
这是我的代码:
public class SplashScreenActivity extends Activity {
private InterstitialAd mInterstitialAd;
private Timer waitTimer;
private boolean interstitialCanceled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
mInterstitialAd.setAdListener(new AdListener()
{
@Override
public void onAdLoaded() {
if (!interstitialCanceled) {
waitTimer.cancel();
mInterstitialAd.show();
}
}
@Override
public void onAdFailedToLoad(int errorCode) {
startHomeMain();
}
});
waitTimer = new Timer();
waitTimer.schedule(new TimerTask() {
@Override
public void run() {
interstitialCanceled = true;
SplashScreenActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
startHomeMain();
}
});
}
}, 5000);
} // end of onCreate implementation.
private void startHomeMain() {
Intent intent = new Intent(this, HomeMain.class);
startActivity(intent);
finish();
}
@Override
public void onPause() {
waitTimer.cancel();
interstitialCanceled = true;
super.onPause();
}
@Override
public void onResume() {
super.onResume();
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else if (interstitialCanceled) {
startHomeMain();
}
}
}
我试图将非页内广告整合到初始屏幕活动中 通过使用此tutorial ..但广告未加载。
谁能告诉我问题出在哪里?
预先感谢
答案 0 :(得分:0)
Google广告加载至少需要6秒钟的时间,并且您在代码中将计时器设置为5秒钟,因此这就是“启动画面”活动结束但广告未展示的原因
尝试将计时器设置为大于6秒,并显示添加破坏活动的方法。
答案 1 :(得分:0)
移除计时器并添加进度对话框,并在onAdLoaded Dismiss对话框中显示广告以及在onFailedtoLoad中显示Dismiss对话框