问题描述
我用 gridview 适配器创建了一个音板(所以没有机会在声音按钮上设置插页式广告)我还有一个带有三个标签的导航栏,所以我决定在第二个片段上设置插页式广告,如下所示:
I created a soundboard with a gridview Adapter (so no chance to set the Interstitial Ad on a sound button) I also have a navigationbar with three tabs, so I decidet to set the Interstitial ad on the second fragment like this:
public class SecondFragment extends Fragment {
private InterstitialAd mInterstitialAd;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView=inflater.inflate(R.layout.second_layout,container,false);
final AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd = new InterstitialAd(getActivity());
mInterstitialAd.setAdUnitId("MYID");
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if(mInterstitialAd.isLoaded()){
mInterstitialAd.show();
}
}
@Override
public void onAdClosed() {
}
});
return rootView;
}
但问题是广告延迟了 3 秒弹出,这就是为什么我收到了来自 AdMob 的邮件,我必须正确设置插页式广告,而不是像以前那样.
But then the problem was that the Ad pops up with a 3 second delay, thats why I received a mail from AdMob that I have to set the Interstitial ad correctly and not like I did before.
所以我的问题是,在这种情况下你会怎么做?您会在哪里设置 InterstitialAd?
So my question is, what would you do in this case? Where would you set the InterstitialAd?
这是我的应用程序,3 个完整的带有声音按钮的片段:https://gyazo.com/1ecd359b38fcfe0606bb3e74b684f16e
This is my App, 3 fragments full with sound buttons: https://gyazo.com/1ecd359b38fcfe0606bb3e74b684f16e
推荐答案
从您的代码中,您发出加载广告的请求,然后当您的广告被加载时,您就会显示该广告.
From your code you're giving request to load ad then when your ad is loaded then you show that ad.
加载广告总是有延迟,所以我的建议是加载您的广告之前是背景而不显示该广告.每当您只想展示广告时,请检查您的插页式广告是否已准备好展示,如果是,则展示.
There's always a delay in loading ads so my suggestion is load your ad previously is background and not show that ad. whenever you want to show ad only check is your interstitial is ready to show, if yes show.
在后台立即调用 createInterstitial()
,之后当您想要显示插页式广告时,调用 showInterstitial()
.
Call createInterstitial()
at once in background and after that whenever you want to show interstitial Ad, call showInterstitial()
.
public void crateInterstitial(){
interstitialAd = new InterstitialAd(this.activity);
interstitialAd.setAdUnitId(AD_UNIT_ID_INTERSTITIAL);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// not call show interstitial ad from here
}
@Override
public void onAdClosed() {
loadInterstitial();
}
});
loadInterstitial();
}
public void loadInterstitial(){
AdRequest interstitialRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialRequest);
}
public void showInterstitial(){
if (interstitialAd.isLoaded())
interstitialAd.show();
else
loadInterstitial();
}
这篇关于在这种情况下如何正确展示插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!