I have even switched to Live ads and see the exact same behaviour. When I compile the app and run it on the phone, the ads load the first time, display and work as expected. When I try to load it a second time within the same session, ads don't get loaded. The code below is for test-ad-unit.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
rewardedAd = RewardedAd(this, "ca-app-pub-3940256099942544/5224354917")
initialiseAds()
}
private fun initialiseAds() {
MobileAds.initialize(this) { initializationStatus ->
val statusMap = initializationStatus.adapterStatusMap
for (adapterClass in statusMap.keys) {
val status = statusMap[adapterClass]
Log.d(
TAG, String.format(
"Adapter name: %s, Status: %s, Latency: %d",
adapterClass, status!!.initializationState, status.latency
)
)
}
// Start loading ads here...
loadAds()
}
}
private fun loadAds() {
if(!rewardedAd.isLoaded) {
Log.d(TAG, "Ad not ready")
runOnUiThread {
val adLoadCallback = object : RewardedAdLoadCallback() {
override fun onRewardedAdLoaded() {
// Ad successfully loaded.
Log.d(TAG, "Ad ready.")
}
override fun onRewardedAdFailedToLoad(adError: LoadAdError) {
// Ad failed to load.
Log.d(TAG, "Ad can't load. ${adError.message}")
}
}
rewardedAd.loadAd(AdRequest.Builder().build(), adLoadCallback)
}
}
} else {
Log.d(TAG, "Ad ready, no need to load Ads.")
}
}
private fun showAd() {
if (rewardedAd.isLoaded) {
val activityContext: Activity = this@MainActivity
val adCallback = object : RewardedAdCallback() {
override fun onRewardedAdOpened() {
// Ad opened.
Log.d(TAG, "Ad opened.")
}
override fun onRewardedAdClosed() {
// Ad closed.
Log.d(TAG, "Ad closed.")
loadAds()
}
override fun onUserEarnedReward(@NonNull reward: RewardItem) {
// User earned reward.
failedOnceAlready = false
Log.d(TAG, "Full credit unlocked.")
}
override fun onRewardedAdFailedToShow(adError: AdError) {
// Ad failed to display.
Log.d(TAG, "Failed to display the ad. ${adError.message}")
}
}
Log.d(TAG, "Showing video ad.")
rewardedAd.show(activityContext, adCallback)
} else if (failedOnceAlready) {
failedOnceAlready = false
Log.d(TAG, "Failed to show the ads a second time.")
loadAds()
} else {
failedOnceAlready = true
loadAds()
Log.d(TAG, "Failed to show the ads first time.")
showTimerDialog()
}
}
The logs are very interesting. As you can see the ads are only ready once. And never again.
2020-12-27 14:35:14.154 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:35:14.747 25732-25732/ D/MainActivity: Adapter name: com.google.android.gms.ads.MobileAds, Status: READY, Latency: 4
2020-12-27 14:35:14.748 25732-25732/ D/MainActivity: Adapter name: com.google.ads.mediation.ironsource.IronSourceMediationAdapter, Status: READY, Latency: 902
2020-12-27 14:35:14.748 25732-25732/ D/MainActivity: Adapter name: com.google.ads.mediation.adcolony.AdColonyMediationAdapter, Status: READY, Latency: 847
2020-12-27 14:35:14.748 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:35:17.396 25732-25732/ D/MainActivity: Ad ready.
2020-12-27 14:40:53.353 25732-25732/ D/MainActivity: Connect
2020-12-27 14:41:18.803 25732-25732/ D/MainActivity: Ad ready, no need to load Ads.
2020-12-27 14:41:19.921 25732-25732/ D/MainActivity: Showing video ad.
2020-12-27 14:41:19.991 25732-25732/ D/MainActivity: Ad opened.
2020-12-27 14:41:25.228 25732-25732/ D/MainActivity: Full credit unlocked.
2020-12-27 14:41:25.270 25732-25732/ D/MainActivity: Connect
2020-12-27 14:41:30.237 25732-25732/ D/MainActivity: Ad closed.
2020-12-27 14:41:30.237 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:41:30.281 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:42:02.400 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:42:05.660 25732-25732/ D/MainActivity: Ad not ready
2020-12-27 14:42:05.662 25732-25732/ D/MainActivity: Failed to show the ads first time.
2020-12-27 14:42:20.707 25732-25732/ D/MainActivity: Failed to show the ads a second time.
Is this the correct way to load the ads?