我在我的应用中展示插页式广告,广告加载和显示完美无缺,但问题在于当我点击关闭按钮时广告没有关闭,我必须退出应用才能关闭它们。我创建了一个新的项目并在新项目中检查广告,它们可以正常工作并在返回按钮上关闭,但在我的主要应用程序中,广告一旦显示给用户就无法关闭。这是我的Admob类。
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);
}
});
}
}
这是我在活动中展示它们的方式。
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
Admob.createLoadInterstitial(this,null);
我已经在 Mainfest 中初始化了这个
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
我在stackoverflow上看到了一些类似的问题,但没有一个得到答案,所以任何帮助都将不胜感激