简体   繁体   中英

AdMob interstitial ads are slow to load

I have placed some interstitial ads in my application, where the ads are placed when I click the button to enter new activity. However, I can't enter the activity while the ad is still loading, sometimes the ad appears after a while, so during that time I can't enter the targeted activity.

Is there a way to get interstitial ads to appear quickly or a solution so that users don't think my app has an error?

here my code:

loadInterstitial();

    findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (interstitialAd !=null) {
                interstitialAd.show(MainActivity.this);

                interstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){
                    @Override
                    public void onAdDismissedFullScreenContent() {
                        // Saat iklan ditutup
                        loadInterstitial();
                        startActivity(new Intent(MainActivity.this, Tips.class));
                    }

                    @Override
                    public void onAdFailedToShowFullScreenContent(AdError adError) {
                        // Saat iklan gagal muncul
                        Toast.makeText(getApplicationContext(), getString(R.string.on_ad_failed_show_fs), Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onAdShowedFullScreenContent() {
                        // saat iklan sudah muncul
                        interstitialAd = null;
                    }
                });
            }
        }
    });

    
private void loadInterstitial() {
    InterstitialAd.load(this, "ca-app-pub-0420793xxxxxxx/xxxxxx", new AdRequest.Builder().build(),
            new InterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull InterstitialAd interstitial) {
                    // Saat iklan berhasil dimuat
                    interstitialAd = interstitial;
                }

                @Override
                public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                    // Saat iklan gagal dimuat
                    interstitialAd = null;
                    startActivity(new Intent(MainActivity.this, Tips.class));
                    Toast.makeText(getApplicationContext(), getString(R.string.on_ad_failed_to_load) + loadAdError.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
            });
}

As stated in the Google AdMob Help section:

Carrier network latency can potentially affect delivery of interstitial ads in your mobile app. This latency may cause the ad to appear on the user's screen at inopportune or unintended times. Consider what the user may be doing in the time window that the interstitial ad is expected to appear, and consider pre-loading your interstitial ads to reduce latency when displaying them to your users.

In the Interstitial Ads documentation along with the best practices that are provided, there is also this useful tip:

Allow for adequate loading time. Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance by calling loadAd() before you intend to call show() can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.

So, it is suggested that you preload your ad by calling your loadInterstitial() function as early as possible to provide it as much loading time as you can.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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