'Admob interstitial ads are not closing
I'm showing interstitial ad in my app and ads are loading and displaying perfectly but the issue is that ads are not closing when I click cross button on back button I have to quit my app to close them I created a new project and checked the ads in new project they are working fine and closing on back button but in my main app ads are not closing once they displayed to user this is my Admob class
public class Admob {
public static InterstitialAd mInterstitial; // Interstital
private static AdView mAdView; // banner
public static void createLoadInterstitial(final Context context, View view)
{
mInterstitial = new InterstitialAd(context);
mInterstitial.setAdUnitId(context.getResources().getString(
R.string.admob_showIntersitial_ad_unit_id));
mInterstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
showInterstitial();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
@Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
}
@Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
// Called when an ad leaves the app (for example, to go to the
// browser).
super.onAdLeftApplication();
}
});
loadInterstitial();
}
public static void loadInterstitial() {
mInterstitial.loadAd(new AdRequest.Builder().
addTestDevice("").//ca-app-pub-3940256099942544/1033173712
build());
}
public static void showInterstitial() {
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
public static void createLoadBanner(final Context context, View view) {
mAdView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().
addTestDevice("").//ca-app-pub-3940256099942544/6300978111
build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
}
@Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
}
@Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
@Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
super.onAdLeftApplication();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
}
});
}
}
This is how I show them in my activity
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
Admob.createLoadInterstitial(this,null);
I have initialize this in Mainfest also
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
I saw same questions on stackoverflow but none of them is answered the solution so any help will be really appreciated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|