Best Practices

Android (or rather Dalvik) has some strange performance characteristics at times. To round off this chapter, we'll present to you some of the most important best practices that you should follow to make your games as smooth as silk.

  • The garbage collector is your biggest enemy. Once it obtains CPU time for doing its dirty work, it will stop the world for up to 600 ms. That's half a second that your game will not update or render. The user will complain. Avoid object creation as much as possible, especially in your inner loops.
  • Objects can get created in some not-so-obvious places that you'll want to avoid. Don't use iterators, as they create new objects. Don't use any of the standard Set or Map collection classes, as they create ...

Get Beginning Android 4 Games Development 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.