【问题标题】:Interstitial Ad not show in splash screen activity插页式广告未显示在初始屏幕活动中
【发布时间】:2018-08-30 11:27:51
【问题描述】:

我正在尝试将插页式广告集成到初始屏幕活动中 通过使用这个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 .. 但广告没有加载。

谁能告诉我问题出在哪里?

提前致谢

【问题讨论】:

  • 你能分享你关于加载广告的日志吗?应该有广告的错误代码
  • 已经在真机上测试过了?加载问题在模拟器上正常吗?
  • 是,但不展示广告。我在其他活动中有插页式广告效果很好.. 但在这个地方没有

标签: java admob interstitial


【解决方案1】:

Google 广告至少需要 6 秒才能加载,并且在您的代码中您已将计时器设置为 5 秒,这就是您的启动画面活动完成但未显示广告的原因

尝试设置大于6秒的计时器,并显示add on destroy方法的activity。

【讨论】:

  • 感谢您的回复我已经尝试了 10 秒但没有工作
【解决方案2】:

删除计时器并添加进度对话框并在 onAdLoaded 中关闭对话框并显示广告以及在 onFailedtoLoad 中关闭对话框

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多