AdMob Interstitial und error isLoaded müssen im Haupt-UI-Thread aufgerufen werden

Nach User William schlage ich vor, meinen Code für die Schaltung von Interstitial-Anzeigen für dieses @ zu änder

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    //setDebugMode(true);
    initialiseAccelerometer();

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(getResources().getString(R.string.InterstitialAd_unit_id));

    interstitial.setAdListener(new AdListener() {
        public void onAdClosed() {
            // Create another ad request.
            final AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
            interstitial.loadAd(adRequest);
        }
    });
    // Create ad request.
    final AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    interstitial.loadAd(adRequest);
}

und zum Anzeigen dieser:

public synchronized void GameOver() {
    if (lives_left > 0) {
        //success! - game passed - save score
        ScoreManager.save_localscore_simple(score_times[currentLevel], "" + currentLevel, false);

        if (Level_Buttons.length >= currentLevel + 1)
            ScoreManager.save_localscore_simple(unlocked, "unlock" + (currentLevel + 1));

        if (sound_success != 0 && !sound_muted)
            sp.play(sound_success, 1, 1, 0, 0, 1);

        //open interstitial ad
        if (interstitial.isLoaded()) {
            interstitial.show();
        }


    } else {
        //game not passed
        if (sound_gameover != 0 && !sound_muted)
            sp.play(sound_gameover, 1, 1, 0, 0, 1);
    }


    //open interstitial ad
    if (interstitial.isLoaded()) {
        interstitial.show();
    }

    StopMusic();
    state = GAMEOVER;

}

Bei jedem Gameover im Spiel erhalte ich diesen Fehler:

W/dalvikvm(20469): threadid=11: thread exiting with uncaught exception      (group=0x4180bda0)
E/AndroidRuntime(20469): FATAL EXCEPTION: Thread-67543
E/AndroidRuntime(20469): Process: com.test.mygame, PID: 20469
E/AndroidRuntime(20469): java.lang.IllegalStateException: isLoaded must be      called on the main UI thread.
E/AndroidRuntime(20469):    at     com.google.android.gms.common.internal.bh.b(SourceFile:251)
E/AndroidRuntime(20469):    at  com.google.android.gms.ads.internal.b.e(SourceFile:345)
E/AndroidRuntime(20469):    at com.google.android.gms.ads.internal.client.m.onTransact(SourceFile:66)
E/AndroidRuntime(20469):    at android.os.Binder.transact(Binder.java:361)
E/AndroidRuntime(20469):    at com.google.android.gms.internal.ap$a$a.isReady(Unknown Source)
E/AndroidRuntime(20469):    at com.google.android.gms.internal.au.isLoaded(Unknown Source)
E/AndroidRuntime(20469):    at com.google.android.gms.ads.InterstitialAd.isLoaded(Unknown Source)
E/AndroidRuntime(20469):    at com.test.mygame.MainGame.GameOver(MainGame.java:1128)
E/AndroidRuntime(20469):    at com.test.mygame.MainGame.Step(MainGame.java:773)
E/AndroidRuntime(20469):    at com.test.nudge.Screen.run(Screen.java:207)
E/AndroidRuntime(20469):    at java.lang.Thread.run(Thread.java:841)

Was ist hier falsch? Bitte erkläre mir dies so einfach wie möglich, da ich vorher noch kein Programmierwissen habe :) Danke!

Antworten auf die Frage(4)

Ihre Antwort auf die Frage