O'Reilly logo

Learning AndEngine by Martin Varga

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Storing values

From time to time, we need to persist some values. Typical examples are a high score or the settings of our game. AndEngine doesn't have any built-in mechanism for this, but we can use the Android SDK to achieve it.

There are two ways. A simple way is to use shared preferences, which is a key-value persistent storage. A more robust but more complicated way is to use the SQLite database, which is accessible from every Android application. We are going to use the simple way to store the high score and sound settings.

Using preferences

Each application has access to its Preferences object. It's basically a key-value map. It is very simple to use preferences, but it's easy to make a mistake. First, we need to initialize the storage. This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required