这是我的 list 文件:

<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" />

这是我的 Activity :
 @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/40858027/

10-08 23:37