如何使Admob的间隙表演刻不容缓? [英] How to make Admob interstitial show without delay?

查看:135
本文介绍了如何使Admob的间隙表演刻不容缓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的游戏在Android SDK中进行。当用户具有水平失败我想填隙出现,更多或更少的确切的那一刻。问题是从code我有,是一个@延时5秒的那一刻起间质性功能开始到间质出现(在LogCat中选中这里是code:

I have a simple game made in android sdk. When the user has level failed I want an interstitial to appear, more or less exactly at that moment. The problem is from the code I have, is a @5 seconds delay from the moment that interstitial function start until interstitial appear(checked in LogCat. Here is the code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    if (getResources().getString(R.string.InterstitialAd_unit_id).length() > 0) {
        // Create the interstitial
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId(getResources().getString(R.string.InterstitialAd_unit_id));

        // Create ad request.
        adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
    }
    //initialise banner ad
    this.BANNER_AD_UNIT_ID = getResources().getString(R.string.BannerAd_unit_id);
    showBanner();

}

public void openAd() {
    if (getResources().getString(R.string.InterstitialAd_unit_id).length() > 0) {
        runOnUiThread(new Runnable() {
            public void run() {
                if (!interstitial.isLoaded()) {
                    interstitial.loadAd(adRequest);
                }
                interstitial.setAdListener(new AdListener() {
                    public void onAdLoaded() {
                        interstitial.show();
                    }

                });

            }
        });
    }
}

有没有什么办法来缓存间的函数被调用之前。这延迟实在是太差了.... 谢谢!

Is there any way to cache the interstitial before that function is called. That delay is really bad.... Thanks!

推荐答案

您的问题是,你正在尝试加载广告,并显示在同一时间。装载要求是缓慢的网络请求。这是永远不会给你你所追求的体验。

Your problem is that you are attempting to load the ad and show it at the same time. Loading requires a network request which is slow. This is never going to give you the experience you are after.

推荐的做法是叫 interstitial.loadAd(adRequest)为您的游戏或水平的开始。然后在你的水平通话结束

Recommended practice is to call interstitial.loadAd(adRequest) at the start of your game or level. And then at the end of your level call

if (interstitial.isAdLoaded() {
    interstitial.show();
}

这篇关于如何使Admob的间隙表演刻不容缓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆