Chapter 10
Storing and Retrieving Game Information
In This Chapter
Using Android’s SharedPreferences
file
Reading and writing XML
Creating SQLite databases
Playing games on a mobile device comes with the inherent issue that the device is often used for other things — like phone calls — which means your game is more likely to be interrupted at some point than it would be on devices like PCs or consoles. Even when the game itself is not disrupted, there’s usually information that you would like to persist (store between sessions), even if the gaming sessions are bite-size.
Common examples of data you’d want to persist include
Options (such as sound/music settings)
High scores
The state of an individual game (where game elements were located; what the score was, and so on)
When it comes to storing and retrieving data, you have several options:
SharedPreferences
(key-value pairs for ...
Get Android Game Programming For Dummies 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.