3

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.

Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
  • Could you post the contents of `prepareRequestBuilder()` as well? – Michiel Dec 04 '19 at 10:26
  • Hello @Michiel , I just added it. Thx! The XXX are because I don't want to post my Test Id's – Francisco Durdin Garcia Dec 04 '19 at 10:35
  • Is the app not responding, or is the app not showing? Are you calling`if (ad?.isLoaded) ad?.show()` as well? – Michiel Dec 04 '19 at 10:45
  • why you choose onResume() to call prepareInterstitialBanner() instead of onCreate() ? – Radhey Dec 04 '19 at 10:49
  • @Michiel The app is not responding because UI thread get block on the `loadAd` call. on the last line of the method I posted above. It never goes beyond that. The show method is on a different place, but it never get call. @Radhey For nothing special, usually because my onCreate is a bit dynamic because of the permissions that the user gives to the app. I don't think that will be causing the problem, tried already to swap it and still happening – Francisco Durdin Garcia Dec 04 '19 at 13:21

0 Answers0