adMob interstitial delay

Asked

Viewed 124 times

0

I have a problem with delay in some interstitial ads adMob, which can cause undue clicks, until these days it was all right, but I don’t know why from one hour to the next started with this.

My code follows the Google standard, I suspect it is some advertisements that do not load on time causing this delay to show.

The code in Java is this:

private void requestNewInterstitial() {
    AdRequest adRequest = new AdRequest.Builder().build();
    interstitial.loadAd(adRequest);
}

In the onCreate

   // Criar o anúncio intersticial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(ADMOB_INTERSTICIAL); //meu codigo adMob
    // importante colocar este codigo aqui
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
        }
    });

    requestNewInterstitial();

The method:

// Chamar displayInterstitial() quando você estiver pronto para exibir um
// intersticial.
public void displayInterstitial() {
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
}

I ran several tests, and I realized the best way was to remove AndroidManifest.xml this line here.

android:theme="@android:style/Theme.Translucent" 

On the Google website asks to stay like this,

android:configChanges="keyboard|keyboardHidden|orientation|
screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent" />

But it’s not rolling with this line Theme, I have some apps in landscape mode that looks cool with this line there, but apparently it won’t work.

Does anyone know what might be going on?

1 answer

0

Try to do it that way :

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        interstitialAd = new InterstitialAd(Main.this);
        interstitialAd.setAdUnitId(getString(R.string.adMobInter));
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice(getString(R.string.adMob_test))
                .build();
        interstitialAd.loadAd(adRequest);

        interstitialAd.setAdListener(new AdListener() {


            @Override
            public void onAdLoaded() {
                
                   displayInterstitial();
                
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                
                onMain();


            }

            @Override
            public void onAdClosed() {
                
                onMain();

            }
        });

    }

    public void displayInterstitial() {
      
        if (interstitialAd.isLoaded())  {
            interstitialAd.show();

        }
    }

    public void onMain() {

        setContentView(R.layout.main); }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.