How do I get the interfacial ad between an Activity and another?

Asked

Viewed 62 times

0

I think I did everything correctly, but the application jumps to the next Activity without appearing anything.

public class...

  private FirebaseAnalytics mFirebaseAnalytics;
  private AdView adView01;
  private AdRequest adRequest01;
  private InterstitialAd adInter01;

  onCreate()...

    MobileAds.initialize(this, "ca-app-pub-6843243039127549/2394454715");
    adView01=(AdView)findViewById(R.id.adView03);
    adRequest01=new AdRequest.Builder().build();
    adView01.loadAd(adRequest01);
    adInter01=new InterstitialAd(this);
    adInter01.setAdUnitId("ca-app-pub-6843243039127549/3871187910");
    adInter01.loadAd(adRequest01);

    mFirebaseAnalytics=FirebaseAnalytics.getInstance(this);

  onClick()...

    case R.id.btnCompras:

      adInter01.show();
      Intent it01 = new Intent(this, MainActivity02.class);
      startActivity(it01);
      break;

I think it may be some problem to be using the same Adrequest that I use for the banner, but the banner keeps working. (in this and the other Activity as well)

inserir a descrição da imagem aqui

The application does not accuse any error, so it gets harder to detect which cause does not work

Site where I picked up information to place interticial ad => https://developers.google.com/admob/android/interstitial

EDIT 01 ----------------------------------

I did what I was told, see the code below:

case R.id.btnCompras:

  adInter01.setAdListener(new AdListener(){
    @Override
    public void onAdClosed(){
      Intent it01 = new Intent(this, MainActivity02.class);
      startActivity(it01);
    }
  });
  break;

But the attempt to implement the code, presented an error (we could not transcribe, so the image):

inserir a descrição da imagem aqui

  • There is a tutorial perfectly explained on the Admob website.

  • @Márciooliveira could give me the link?

  • 1

    https://developers.google.com/admob/android/interstitial

1 answer

0

I believe you should call the new Activity when the ad is closed, using Adlistener

mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLeftApplication() {
            // Code to be executed when the user has left the app.

        }

        @Override
        public void onAdClosed() {
            // Code to be executed when when the interstitial ad is closed.
            //aqui tu chama a nova activity
    });
  • I did as you indicated, it was a mistake. Check Edit

  • instead of This, try passing the other context, like getApplicationContext()

  • Did not accuse any error, however no ad is displayed and neither changes from Activity

Browser other questions tagged

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