You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ads Play Services 21.4.0中onAdDismissedFullScreenContent回调未触发

问题描述

使用最新版Ads Play Services(21.4.0),通过测试应用ID和测试广告ID测试时,发现FullScreenContentCallback的onAdDismissedFullScreenContent函数从未被调用。点击插屏广告内的关闭按钮后,无任何回调函数触发,但其他非错误回调(如onAdClicked、onAdImpression、onAdShowedFullScreenContent)均能正常执行。需要响应广告关闭事件,求原因及解决办法。


相关代码

1. 加载广告代码

InterstitialAd.load(
    context,
    adId,
    AdRequest.Builder().build(),
    createInterstitialAdListener()
)

2. 广告加载监听代码

private fun createInterstitialAdListener(): InterstitialAdLoadCallback {
    return object : InterstitialAdLoadCallback() {
        override fun onAdLoaded(ad: InterstitialAd) {
            super.onAdLoaded(ad)
            L.d { "Interstitial ad loaded..." }
            ad.fullScreenContentCallback = createFullScreenContentCallback("Interstitial")
            interstitialAd = ad
            this@AdsViewManager.onAdLoaded()
        }

        override fun onAdFailedToLoad(error: LoadAdError) {
            super.onAdFailedToLoad(error)
            onAdLoadingError(error.message)
        }
    }
}

private fun createFullScreenContentCallback(type: String): FullScreenContentCallback {
    return object : FullScreenContentCallback() {
        override fun onAdClicked() {
            // 正常触发
            L.d { "[$type] FullScreen ad clicked" }
        }

        override fun onAdDismissedFullScreenContent() {
            // 从未被调用
            L.d { "[$type] FullScreen ad dismissed" }
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdFailedToShowFullScreenContent(error: AdError) {
            onAdLoadingError(error.message)
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdImpression() {
            // 正常触发
            L.d { "[$type] FullScreen ad - IMPRESSION" }
        }

        override fun onAdShowedFullScreenContent() {
            // 正常触发
            L.d { "[$type] FullScreen ad showed..." }
        }
    }
}

3. 广告展示代码

fun show() {
  if (interstitialAd == null) {
   L.e { "Interstitial ad not ready" }
  } else {
    interstitialAd?.show(activity)
    L.d { "Showing interstitial ad..." }
  }
}

日志信息

Interstitial ad loaded...
Showing interstitial ad... 
[Interstitial] FullScreen ad showed... 
[Interstitial] FullScreen ad - IMPRESSION
// 缺少关闭日志,从未出现

可能的原因及解决办法

原因分析

  1. 测试广告的特殊行为:部分AdMob测试插屏广告存在回调逻辑不完整的情况,关闭按钮点击后未正确触发onAdDismissedFullScreenContent。
  2. 生命周期异常:持有InterstitialAd实例的对象(如AdsViewManager)在广告展示期间被销毁或回收,导致回调无法被正常接收。
  3. 回调被覆盖:代码中可能存在其他逻辑重新设置了fullScreenContentCallback,覆盖了原本的回调实例。
  4. 版本兼容性bug:Ads Play Services 21.4.0可能存在已知的回调分发问题,部分场景下关闭事件未正常传递。

解决办法

  • 更换测试广告ID:尝试使用不同的插屏测试广告ID,或切换到测试模式下的真实广告验证回调是否触发。
  • 加固实例生命周期:确保持有InterstitialAd的对象在广告展示期间处于活跃状态,通过强引用避免被GC回收;在Activity/Fragment的生命周期方法中统一管理广告实例的创建与销毁。
  • 检查回调覆盖情况:排查代码中是否有其他地方修改了fullScreenContentCallback,确保仅在onAdLoaded时设置一次且后续未被修改。
  • 回退到稳定版本:暂时降级到Ads Play Services 21.3.0或更早的稳定版本,确认是否是新版本的bug导致的问题。
  • 添加兜底逻辑:在展示广告的Activity中重写onResume方法,手动检查广告状态并执行关闭后的逻辑:
override fun onResume() {
    super.onResume()
    interstitialAd?.let {
        // 执行广告关闭后的清理与业务逻辑
        interstitialAd = null
        // 这里可以添加你的自定义处理代码
    }
}

内容的提问来源于stack exchange,提问作者prom85

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 18:05:18