Home » Android » multiple Button with Interstitial ad

multiple Button with Interstitial ad

Posted by: admin November 1, 2017 Leave a comment

Questions:

i have 3 button on main activity nd i want to show every button click Interstitial ad but problem start here

  InterstitialAd mInterstitialAd;

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




  private void showInterstital() {
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    } else
        openNextActivity();
}


private void openNextActivity() {
    Intent intent=new Intent(MainActivity.this,categories.class);
    startActivity(intent);

}

 private void showInterstital1() {
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    } else
        openNextActivity();
}


private void openNextActivity1() {
    Intent intent=new Intent(MainActivity.this,categories.class);
    startActivity(intent);

}

 private void loadAds() {
    if (ConstatntAd.isaddisplay)
    {



        mInterstitialAd = new InterstitialAd(this);

        mInterstitialAd.setAdUnitId(getString(R.string.admob_interstitial_id));

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
                openNextActivity();
            }
        });

        requestNewInterstitial();

    } 
}

and i call showInterstital() in first button click and loadAds call onCreate method

when i click first button after intertital ad show after adclosed openNextActivity();

when i click second button i want to open openNextActivity1();

so plz help me

Answers: