I am about to port a game that was initially written for iOs and I am having some doubts how certain things should be done.

I have been looking many of the examples of the game loops for android, and almost everywhere the game loop is designed to run in separate thread and not in main UI thread which seems fine and logical to me. However, my game scene is combination of OpenGL graphics and standard android views (buttons, labels, etc...) and by design, the primary game logic and OpenGL drawing would be done in separate thread and rest of the standard stuff would be done in main UI thread.

In many situations, I will need to call functions that should run in game thread from main UI thread and vice versa. As a very basic, simple example, when user performs touch (which is detected in UI thread) the event should propagated and be processed by the game thread.

Do you know some good mechanisms or patterns on how to such cross thread interaction? Is there a simpler solution to a game loop, maybe by not running loop in a separate thread?

  • 1
    Please do not post exactly the same question on multiple sites, we can move questions automatically if you happen to post on the wrong one.
    – yannis
    Apr 10, 2013 at 23:12

1 Answer 1


If you run the loop in a separate thread you will need to keep it synchronized with everything else that will be going on. This should provide you with insight though: https://gamedev.stackexchange.com/questions/651/tips-for-writing-the-main-game-loop

I've not programmed on Android, but I have programmed in Java. If you want to see an example of my game loop you can get the code here: https://github.com/moorej/RetroPlexjava

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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