android 活动停留在进程对话框中,无法转到下一页

hwazgwia  于 2022-12-02  发布在  Android
关注(0)|答案(2)|浏览(104)

所以我最近用最新的admob SDK和依赖项更新了我的代码。它应该在进入下一页之前显示一个间隙广告。运行它时,StartActivity停留在进程对话框上,不会进入下一页。下面是代码

//Start Here
                AdRequest adRequest = new AdRequest.Builder().build();

                InterstitialAd.load(StartActivity.this,StartActivity.this.getString(R.string.main_inter), adRequest,
                        new InterstitialAdLoadCallback() {
                            @Override
                            public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                                // The mInterstitialAd reference will be null until
                                // an ad is loaded.
                                pd.dismiss();

                                mInterstitialAd = interstitialAd;
                                mInterstitialAd.show(StartActivity.this);
                                mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){
                                    @Override
                                    public void onAdClicked() {
                                        // Called when a click is recorded for an ad.
                                    }

                                    @Override
                                    public void onAdDismissedFullScreenContent() {
                                        // Called when ad is dismissed.
                                        // Set the ad reference to null so you don't show the ad a second time.

                                        pd.dismiss();
                                        mInterstitialAd = null;
                                        startActivity(new Intent(StartActivity.this, MainActivity.class));
                                        StartActivity.this.finish();
                                    }

                                    @Override
                                    public void onAdFailedToShowFullScreenContent(AdError adError) {
                                        // Called when ad fails to show.
                                        mInterstitialAd = null;
                                    }

                                    @Override
                                    public void onAdImpression() {
                                        // Called when an impression is recorded for an ad.
                                    }

                                    @Override
                                    public void onAdShowedFullScreenContent() {
                                        // Called when ad is shown.
                                    }
                                });
                            }

                            @Override
                            public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                                // Handle the error
                                mInterstitialAd = null;
                            }
                        });
            }
        });

    }
}
p8h8hvxi

p8h8hvxi1#

您不会在onAdDismissedFullScreenContent时关闭进度对话框

@Override
  public void onAdDismissedFullScreenContent() {
  // Called when ad is dismissed.
  // Set the ad reference to null so you don't show the ad a second time.
  pd.dismiss()
  mInterstitialAd = null;
  StartActivity.this.finish();
}

请始终记住处理对话框状态,否则可能导致窗口泄漏。

wj8zmpe1

wj8zmpe12#

在调用finish()之前启动活动

@Override                               
    public void onAdDismissedFullScreenContent() {
        // Called when ad is dismissed.
        // Set the ad reference to null so you don't show the ad a second time.
        pd.dismiss()
        mInterstitialAd = null;
        startActivity(new Intent(StartActivity.this, NextActivity.class));
        StartActivity.this.finish();
        

}

相关问题