我有一个简单的Android应用,我想在主要活动中添加一个广告。但每当我转到应用中的其他活动并返回主要活动时,它会再次调用广告。有没有办法在用户使用应用程序时只调用一次广告?
以下是代码:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tabpmnth_xm);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-xxxxxxxxxxxx8x/x2xxxxxxxx");
AdRequest aadRequest = new AdRequest.Builder()
.build();
// Begin loading your interstitial.
interstitial.loadAd(aadRequest);
interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
displayInterstitial();
}
});
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}