Answers for "interstitialad on click android"

0

interstitialad on click android

private InterstitialAd mInterstitialAd;   // Initialize

// on create
 MobileAds.initialize(this, getResources()
                .getString(R.string.App_ID));

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
           mInterstitialAd.loadAd(new AdRequest.Builder().build());
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
            //call this method to refresh ad
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
                Intent intent = new Intent(yourActivity.this, NextActivity.class);
                startActivity(intent);
            }
        });
  Button button = findViewById(R.id.button);
  button.setOnClickListener(v -> {
         if (mInterstitialAd != null) {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
                /////inApp Counter
            } else {
                Intent intent = new Intent(yourActivity.this, NextActivity.class);
              startActivity(intent);
            }
        }
        });
Posted by: Guest on June-22-2021

Code answers related to "interstitialad on click android"

Browse Popular Code Answers by Language