in this image there is 8 buttons . now iam using test ads units on this app. this activity i have 8 buttons and every buttons are linked with there targeted activity . my problem is when i click the any button of this 8 it show the admob interstitial ads and send to the targeted activity but when i closed the targeted activity and back to main_activity again and click any button of this 8 buttons the admo interstitial ads is not showing but on button click it open the targeted activity. i want to show admob interstitial ads on everytime when the buttons are clicked. how can is do this?
// Admob Firebase
AdView myadview = new AdView(this);
// AdRequest smartBanner
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// Admob Intarsital
MobileAds.initialize(this,
"ca-app-pub-3940256099942544~3347511713");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
private void initialize() {
linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
linear3 = (LinearLayout) findViewById(R.id.linear3);
linear4 = (LinearLayout) findViewById(R.id.linear4);
button9 = (Button) findViewById(R.id.button9);
button10 = (Button) findViewById(R.id.button10);
button11 = (Button) findViewById(R.id.button11);
button12 = (Button) findViewById(R.id.button12);
button13 = (Button) findViewById(R.id.button13);
button14 = (Button) findViewById(R.id.button14);
button15 = (Button) findViewById(R.id.button15);
button16 = (Button) findViewById(R.id.button16);
textview1 = (TextView) findViewById(R.id.textview1);
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), DhakaActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), KhulnaActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button11.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), RoungpurActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button12.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), SeyletActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button13.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), ChitagongActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button14.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), BorishalActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button15.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), RajshashiActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
button16.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
b.setClass(getApplicationContext(), ChitagongActivity.class);
startActivity(b);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new AdRequest.Builder().build());
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@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.
}
});
}
});
}