0

I copied the code of the interstitial from here https://developers.google.com/mobile-ads-sdk/docs/admob/advanced but it doesnt' work. When the app calls the method interstitial.isLoaded(), it crashes. This is the logcat:

04-06 14:40:09.320  29704-30638/? W/dalvikvm﹕ threadid=16: thread exiting with uncaught exception (group=0x4145e438)
04-06 14:40:09.330  29704-30638/? E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3225
    java.lang.IllegalStateException: isLoaded must be called on the main UI thread.
            at bkm.b(SourceFile:174)
            at xx.e(SourceFile:210)
            at yh.onTransact(SourceFile:66)
            at android.os.Binder.transact(Binder.java:326)
            at com.google.android.gms.internal.ac$a$a.isReady(Unknown Source)
            at com.google.android.gms.ads.InterstitialAd.isLoaded(Unknown Source)
            at com.MyApp.GameActivity.displayInterstitial(GameActivity.java:75)
            at com.MyApp.GameActivity$GameView.onDraw(GameActivity.java:300)
            at com.MyApp.GameActivity$GameLoop.run(GameActivity.java:524)
04-06 14:40:09.330     441-4437/? W/ActivityManager﹕ Force finishing activity...

How is it possible? Can you please explain me step-by-step what I have to do to show this interstitial? Thank you in advance

Hidde
  • 11,493
  • 8
  • 43
  • 68
user3503550
  • 73
  • 1
  • 8
  • It seems that your are calling interstitial.isLoaded() on a secondary thread.. and from the error log it seems that you should do that on the main thread. To help you do that, you should add your code here. – Cata Apr 06 '14 at 12:48
  • I don't call it on a secondary thread, but the method displayInterstitial(), which contains interstitial.isLoaded(), is called from a different thread. Maybe this is the problem? – user3503550 Apr 06 '14 at 12:52
  • That might be the issue, yes :) – Cata Apr 06 '14 at 12:52
  • Ok, I tried to call it in the main loop but it's still not working. I think that the ad never loads – user3503550 Apr 06 '14 at 12:55
  • Could you post your code here please? did you tried in onCreate just to test it? – Cata Apr 06 '14 at 12:57
  • Now it works! But now the problem is that I have to call the method displayInterstitial() from the thread of the game loop, not from the main thread. How can I do that? – user3503550 Apr 06 '14 at 12:58
  • Please see here: http://stackoverflow.com/questions/22847440/how-to-remove-background-from-thread/22847553#22847553 – Cata Apr 06 '14 at 13:05
  • Now it's ok, it works. I just have to correct same little bugs, like the delay on showing the ad. Thank you very much, and sorry for my English that's not perfect! – user3503550 Apr 06 '14 at 13:11

1 Answers1

0

Share my case and solution

I call it from other thread and got this error. I solve it my using Message to sent from other thread to main thread (service/activity). Then make the message handler in main thread to call isLoaded(). It is work.