我正在开发一个Android应用程序,我试图实施非页内广告,但加载需要3 4秒,导致我的应用程序意外点击 请帮助我们预先加载我的添加内容,以便它立即显示在下一个屏幕上。
我的代码位于:
public class AboutActivity extends AppCompatActivity {
private AdView mAdView;
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
interstitial = new InterstitialAd(AboutActivity.this);
interstitial = new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX");
AdRequest adRequest1 = new AdRequest.Builder().build();
interstitial.loadAd(adRequest1);
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if(interstitial.isLoaded()) {
interstitial.show();
}
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
}
}
答案 0 :(得分:0)
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
//Remove show() code from here
}
});
请勿在{{1}}方法内的插页式广告中调用show()
方法。制作一种方法来显示插页式广告,并在您想要展示时调用该方法
onAdLoaded()
您还需要为广告添加听众,并在关闭插页式广告时发出新的广告请求。