我正在使用框架动画,我在我的活动中实施横幅广告和插页式广告,但是当我这样做时,它会减慢我的申请。
这是我的代码:
私人InterstitialAd插页式广告;
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("UNIT ID");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("CC5F2C72DF2B356BBF0DA198")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
如何有效地将admob整合到我的班级中的任何解决方案。
答案 0 :(得分:0)
回复你的评论
我可以将所有的admob代码放在其他课程中并在我的课程中初始化它 主要活动?
是的,例如:AdMob.java class
:
import android.content.Context;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class AdMob {
private InterstitialAd interstitial;
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
void LoadInterstitialAd(Context ctx){
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(ctx);
// Insert the Ad Unit ID
interstitial.setAdUnitId("unit_id");
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("CC5F2C72DF2B356BBF0DA198")
.build();
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
}
您可以通过以下方式在任何地方使用它:
AdMob adMob = new AdMob();
adMob.LoadInterstitialAd(getApplicationContext());
我只展示插页式广告,但也可以为其他广告展示..