Reputation: 2117
According to documentation,
public void onAdClosed ( )
Called when the user is about to return to the application after clicking on an ad.
But how can I detect that the user closes the interstitial Activity? (and not the webpage that opened after clicking on the ad)
The accepted answer in this question seems to be wrong: How to detect when the user dismisses a interstitial in Admob?
(The interstitial is still visible after the user returns to the app).
Upvotes: 3
Views: 3723
Reputation: 867
With AdMob v20.0.0
the AdListener
has been deprecated for the full screen ad formats.
You should now attach a FullScreenContentCallback
and override onAdDismissedFullScreenContent()
on the InstertitialAd
instance passed by the InstertitialAdLoadCallback#onAdLoaded
attached when calling InterstitialAd#load
.
It should look somenthing like this:
InterstitialAd.load(context, unitId, adRequest, object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
// TODO handle error!
}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
interstitialAd.fullScreenContentCallback = object: FullScreenContentCallback() {
override fun onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent()
// TODO Handle here the interstitial dismissed.
}
}
}
})
If you need more information here you can find the official guide made to migrate to v20.0.0
Upvotes: 5