gpt4 book ai didi

android - 在按下返回按钮后显示插页广告?

转载 作者:行者123 更新时间:2023-12-02 03:28:31 26 4
gpt4 key购买 nike

这是我的清单文件:

<activity
android:screenOrientation="portrait"
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />


这是我的活动:

 @Override
public void onBackPressed() {
InterstitialAd interstitialAd= new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);

interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {

if (interstitialAd.isLoaded()) {
interstitialAd.show();
}

}

@Override
public void onAdClosed() {
super.onAdClosed();
finish();

}
});

}


按下后退按钮时,我只能看到2-3次广告屏幕。因此,每按一次后退按钮,如何解决此问题。

最佳答案

好试试

InterstitialAd interstitialAd = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blue);

interstitialAd= new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);

}


@Override
public void onBackPressed() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
finish();
}
});
}else{
super.onBackPressed();
}

}

关于android - 在按下返回按钮后显示插页广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56897743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com