Skip to content Skip to sidebar Skip to footer

Android Lunar Lander Thread Handling Alternatives

Like many of the novices of android programming, I used Lunar Lander as a guide for implementing the SurfaceView. I'm practicing by creating a version of PONG. The basic structure

Solution 1:

Keeping the thread object while focus is lost is certainly possible provided the necessary synchronization is done correctly when you regain focus.

However, for simplicity's sake and to release resources when not in focus, you could extract the game state into a class not owned by the game thread and instead pass it to the thread when starting, allowing you to stop the thread in surfaceDestroyed() as done in the original code.

Obviously a thread object will be garbage for each time you loose focus, but the collection of these meager bytes shouldn't be a problem.

Post a Comment for "Android Lunar Lander Thread Handling Alternatives"