简体   繁体   English

加载延迟的非页内广告

[英]Interstitial ad with load delay

I'm trying to implement an interstitial ad, and I'd like it to load before, in the application it's happening to load along with the action which causes delay and makes the ad appear well after. 我正在尝试实施一个插页式广告,我希望它先加载,然后再在应用程序中加载它,同时还要执行动作,该动作会导致延迟,并使广告在之后效果很好。 I want to make the ad appear right after pressing "adicionar" as shown in the image below: enter image description here 我想在按下“ adicionar”后立即显示广告,如下图所示: 在此处输入图片描述

The code below shows how it was implemented: 下面的代码显示了它是如何实现的:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-8920922366585510/4181958830");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        if (requestCode == ADD_PACK) {
            if (resultCode == Activity.RESULT_CANCELED) {
                if (data != null) {
                    final String validationError = data.getStringExtra("validation_error");
                    if (validationError != null) {
                        if (BuildConfig.DEBUG) {
                            //validation error should be shown to developer only, not users.
                            MessageDialogFragment.newInstance(R.string.title_validation_error, validationError).show(getSupportFragmentManager(), "validation error");
                        }
                        Log.e(TAG, "Validation failed:" + validationError);
                    }
                } else {
                    new StickerPackNotAddedMessageFragment().show(getSupportFragmentManager(), "sticker_pack_not_added");
                }
            }
        }
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded()  {
                mInterstitialAd.show();
            }
        });
    }

I've tried loading the call before these codes but I can not load before. 我已经尝试在这些代码之前加载呼叫,但之前无法加载。

            mInterstitialAd = new InterstitialAd(this);
            mInterstitialAd.setAdUnitId("ca-app-pub-8920922366585510/4181958830");
            mInterstitialAd.loadAd(new AdRequest.Builder().build());

The application is an open source github, the link is below if you want to download to see the complete code and help: DOWNLOAD COMPLETE CODE 该应用程序是一个开源的github,如果您想下载以查看完整的代码和帮助,请点击下面的链接: DOWNLOAD COMPLETE CODE

Put the following into your onCreate method: 将以下内容放入您的onCreate方法中:

mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-8920922366585510/4181958830");
mInterstitialAd.loadAd(new AdRequest.Builder().build());

And put the following into your onActivityResult : 并将以下内容放入您的onActivityResult

if(mInterstitialAd.isLoaded()) {
   mInterstitialAd.show();
}

I had the same problem, and of course I didn't wanted to load the ad on activity creation, so I decided to load the ad on at the same moment the dialog opens, have the "adicionar" button disabled and when the ad was loaded then enable the button. 我遇到了同样的问题,当然我也不想在创建活动时加载广告,因此我决定在对话框打开的同时加载广告,禁用“ adicionar”按钮,以及在加载后启用按钮。

I also decided to add a description to wait on the button to be enabled. 我还决定添加描述以等待按钮启用。

This might not be the solution you are looking for but at least is the most optimal on data loading. 这可能不是您要寻找的解决方案,但至少在数据加载方面是最佳的。 Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM