Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. 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 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?

share|improve this question
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 '13 at 23:12
up vote 1 down vote accepted

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:

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:

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.