切换时不显示 AdMob 插页式广告 activity (Android)

AdMob interstitial not being shown when switching activity (Android)

我目前正在将 AdMob 添加到我的一些应用程序中,但遇到了问题。 我尝试在更改 activity 时显示插页式广告,因为这是不会惹恼用户的地方。

我最初的理解是,显示广告会使 activity 进入暂停模式,并在广告关闭后恢复。

这个假设似乎是错误的,如下代码,activity被直接切换,吐司显示应该显示广告,但只要我不评论startActivity (意图),我从来没有看到广告。

我在 onCreate 中加载广告,然后尝试在点击按钮时触发的另一个空白中显示它(当然,如果它在那个时间点已经完成加载)。

源代码:

@Override
public void onCreate(Bundle SafedInstanceState)
{
    [...]
    LoadAd();
    [...]
}

public void ShowAd(){
    if (interstitial.isLoaded()) {
    interstitial.show();
    }
}

public void LoadAd(){
    String MY_AD_UNIT_ID=getResources().getString(R.string.AdID);
    // Create the interstitial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(MY_AD_UNIT_ID);

    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);
}

public void SWITCHACTIVITY (View view) {
    ShowAd();
    Intent intent = new Intent (this, ANOTHERACTIVITY.class);
    startActivity(intent);
    finish();
}

非常感谢任何关于我在这里做错了什么或如何实现广告显示以及 activity 在广告关闭后切换/关闭的意见。

提前致谢!

好的,所以我解决了这个问题。有点难看,但它正在做我想要它做的事情。 在调用 ShowAd() 之前,我设置了我的意图,然后在广告关闭后触发它:

public void ShowAd(){
        if (interstitial.isLoaded()) {
            interstitial.show();
            interstitial.setAdListener(new AdListener() {
            public void onAdClosed() {
                if (PostAdIntent != null)
                {
                    startActivity(PostAdIntent);
                    PostAdIntent = null;
                    finish();
                };
            }
            });

        } else
        {
            if (PostAdIntent != null)
                {
                startActivity(PostAdIntent);
                PostAdIntent = null;
                finish();
                };
        }
}