I'm struggling recently with Admob because my loadAd
method is freezing the whole application.
There is not too much else to say, but it happens on a release or debugs and depends on the device.
I get isAdIdFakeForDebugLogging
error when this happens, but only in debug. On release, there is no admob trace anywhere. But my code never go beyond ad.loadAd(request)
method. It keeps there loading indefinitely.
I'm calling the prepareInterstitialBanner()
method in the onResume
of my app.
The method looks like:
fun prepareInterstitialBanner() {
try {
if (ad?.isLoaded == true || ad?.isLoading == true) {
return //Already loading
}
ad = InterstitialAd(activity).apply {
adUnitId = activity.getString(R.string.INSTERSTITIAL_AD_ID)
adListener = object : AdListener() {
override fun onAdLoaded() {
Grove.i { "Ad loaded" }
}
override fun onAdClosed() {
Grove.i { "Ad closed" }
activity.finish()
}
override fun onAdFailedToLoad(p0: Int) {
Grove.i { "Ad failed to load: $p0" }
}
}
}
Grove.i { "Loading Interstitial ad" }
ad!!.loadAd(prepareRequestBuilder())
} catch (e: Exception) {
Grove.e(e) { "Ad failed to load" }
Crashlytics.logException(e)
}
}
private fun prepareRequestBuilder(): AdRequest {
return AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("XXX")
.addTestDevice("XXXX")
.build()
}
I didn't change anything of my code in weeks and it stopped working right now. Anyone have gone thought this issue? Also, any idea about how to move this to BG thread.