I try to write a little game using android and have some problems with threading. The mainloop of the game runs in this own thread and basically just does something like this:
public void run() {
while (true) {
NativeGameLib.gameTick(t);
}
}
Now I want to pass touch inputs to my NativeGameLib. I thought I use the onTouchEvent() of the view in the UI-thread, create a runable inside and let it execute on the main-loop thread.
But I don't really get how to do it. I have seen that there is a Handler and a Looper class and that I can use the handler to post runables to the messageQueue and the Looper.loop() function to process the queue.
As far as I understand it, the loop() function endlessly checks for new messages and therefore blocks the thread. So, how can I combine it with my thread. I want to do something like this in the thread:
public void run() {
while (true) {
processMessageQueue();
NativeGameLib.gameTick(t);
}
}
Any ideas? Thanks.