Implementing the game loop with a thread

Now we have learned about the game loop, threads, try and catch, we can put it all together to implement our game loop.

We will add the entire code for the game loop including writing two methods in the PongGame class to start and stop the thread which will control the loop.

After we have done this we will again need to do a little bit more theory. The reason for this is that the player can quit the app whenever they like, and our game's thread will need to know so it can stop itself. We will examine the Android Activity lifecycle which will give us the final pieces of the puzzle that we need before we run our game.

Implementing Runnable and providing the run method

Update the class declaration by implementing ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.