Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a very novice android developer but also created a game using andEngine successfully. Now I want to integrate Scoreloop and everything is fine with Leaderboard view and TOS view, except I am having hard time submitting scores from a game scene. I implemented OnScoreSubmitObserver in the main BaseGameActivity (GameActivity). I used the following line inside the onCreateEngineOptions method:


I also declared the override method perfectly inside GameActivity as mentioned in the scoreloop tutorial:

public void onScoreSubmit(int status, Exception error) {
    // TODO Auto-generated method stub
    //Calls the ShowResultOverlayActivity. Make sure you have modified the
    //AndroidManifest.xml to reference this overlay class.
    startActivity(new Intent(this, ShowResultOverlayActivity.class));

Now I want to submit score from inside a scene using the following line:

ScoreloopManagerSingleton.get().onGamePlayEnded(score, null);

But this shows the following error:

java.lang.IllegalStateException: you are not calling from the main thread context

I also tried implementing OnScoreSubmitObserver on the scene class and tried calling each line mentioned above inside the scene class using "activity" instead of "this", as "activity" is an instance of the GameActivity. but it also shows the same error. Please help.

share|improve this question
So which thread are you calling onGamePlayEnded function from? (also, this isn't specific to game development, you should probably ask on – Byte56 Sep 20 '13 at 15:27
I totally don't know what is the deal with a thread here. It only works only if I call it directly inside the GameActivity. But I need to call it from a game scene, which is not working. – Nafis Sep 20 '13 at 15:39
up vote 2 down vote accepted

Create a Runnable object that executes the update to Scoreloop, then run that object from whatever thread you like with runOnUIThread. This will always ensure the code runs on the same thread.

Your runnable would look something like:

public class ScoreLoopUpdater implements Runnable {
  private float score;
  public ScoreLoopUpdater (Float _score) {
    this.score = _score;

  public void run() {
    ScoreloopManagerSingleton.get().onGamePlayEnded(score, null);

So using it would look like:

ScoreLoopUpdater scoreLoopUpdater = new ScoreLoopUpdater(finalScore);

If the UI thread doesn't work, you can try the same on the "main" thread:

Handler mainHandler = new Handler(context.getMainLooper());;
share|improve this answer
Didn't work. It shows the exact same error. – Nafis Sep 20 '13 at 16:49
I am having a sense that I should use runOnUpdateThread instead of using runOnUiThread. I will let you know after trying. – Nafis Sep 20 '13 at 17:06
Nope, sorry, it's the same error!! – Nafis Sep 20 '13 at 17:27
Please update the question with the full stack trace. – Byte56 Sep 20 '13 at 17:28
Yes, problem is solved. Your solutions are correct. It's just I used "ScoreloopManagerSingleton.get().onGamePlayEnded(score, null);" twice; one was hiding somewhere else. That one was showing the same error all the time. I beg your pardon for this inconvenience. – Nafis Sep 20 '13 at 17:41

The runOnUiThread solution doesn't work for me, because I call it when game resume, my workaround solution is to use TimerHandler:

protected void onResume() {
    final TimerHandler getTimerHandler = new TimerHandler(0.5f, new ITimerCallback() {
        public void onTimePassed(final TimerHandler pTimerHandler) {
            if (!AccountUtils.checkSession()) {
                ResourceManager.getInstance().getCurrentScene().alert("Session timeout!", new IParamCallback() {
                    public void onCallback(final Object param) {
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.