Android Question The ad unit ID must be set on InterstitialAd before show is called.

Discussion in 'Android Questions' started by Filippo, Nov 14, 2018.

  1. Filippo

    Filippo Expert Licensed User

    Hi,

    this message comes from Crashlytics Report.
    How can it happen?

    Code:
    Sub Activity_Create(FirstTime As Boolean)
    ...
        
    'Werbung initialisieren
        If Not(Starter.IsProVersion) Then
            
    'Admob-Interstitial
            AdView1.Initialize("AdView1","ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxx")
            LoadAd
        
    End If
    ...
    End Sub

    Sub LoadAd
        
    'Log("LoadAd")
        Dim builder As AdRequestBuilder
        builder.Initialize
        
    Dim consent As ConsentManager = Starter.consent
        
    If consent.IsRequestLocationInEeaOrUnknown Then
            
    If consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
                builder.NonPersonalizedAds
            
    Else if consent.ConsentState = consent.STATE_UNKNOWN Then
                
    Return
            
    End If
        
    End If
    #if not(Release)
        builder.AddTestDevice("xxxxxxxxxxxxxxxx") 'Samsung A5(2017)
    #End If
        AdView1.LoadAdWithBuilder(builder)
    End Sub

    Sub AdView1_ReceiveAd
        
    'Log("AdView1_ReceiveAd")
        AdView1.Show
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Does it work if you call LoadAd? Are you sure that AdView type is InterstitialAd?
     
  3. Filippo

    Filippo Expert Licensed User

    Yes, without problems! As always, however, I can not reproduce the error with my test devices.

    Yes ;)
    upload_2018-11-14_15-45-8.png

    The error is currently on the following devices:
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    1. Catch this error with Try / Catch block.

    2. Your code looks correct. The ad unit is set when you call Initialize.

    Are you calling LoadAd multiple times? Make some tests and kill the activity and recreate it while the ad is loaded.
     
  5. Filippo

    Filippo Expert Licensed User

    I call "LoadAd" in 3 different Activity each in "Activity_Create" 1 times.

    Thanks, I have to try that.
     
  6. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Maybe also try using AdView1.Ready before you call AdView1.Show. Maybe there's a slight delay between when ReceiveAd is fired & it's actually ready.

    If you're using Firebase Analytics you could log true & false results from AdView1.Ready - that way you can confirm (or not) if sometimes the ad isn't actually ready when ReceiveAd is fired.

    - Colin.
     
    Filippo likes this.
  7. Filippo

    Filippo Expert Licensed User

    Thanks for the tip, it looks better now. ;)

    Code:
    Sub AdView1_ReceiveAd
        
    'Log("AdView1_ReceiveAd")
        If AdView1.Ready Then AdView1.Show
    End Sub
     
    Computersmith64 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice