所有其他的InterstitialAd监听器都在工作,但只有onAdLoaded没有工作。
我已经为所有的监听器设置了toast,但只有onAdLoaded不会被调用,而其他的都正常工作。
为什么只有onAdClicked()不起作用?这个方法有什么问题吗?
代码
public class TestActivity extends AppCompatActivity {
InterstitialAd mInterstitialAd;
AdRequest adRequest;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-9547225037870226/6863551510");
adRequest = new AdRequest.Builder()
.build();
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
Toast.makeText(TestActivity.this, "ad failed to load", Toast.LENGTH_SHORT).show();
}
public void onAdLoaded() {
Toast.makeText(TestActivity.this, "ad loaded", Toast.LENGTH_SHORT).show();
showInterstitial();
}
@Override
public void onAdOpened() {
super.onAdOpened();
Toast.makeText(TestActivity.this, "ad open", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdImpression() {
super.onAdImpression();
Toast.makeText(TestActivity.this, "ad impression", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed() {
super.onAdClosed();
Toast.makeText(TestActivity.this, "ad close", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClicked() {
super.onAdClicked();
Toast.makeText(TestActivity.this, "ad clicked", Toast.LENGTH_SHORT).show();
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
}