How to store user data both offline and online

Hi all.

I’m making an Android game (offline/singleplayer runner game) and I need to store user variables, of course.

So I want to use device storage for local saving (UserDefault or sqlite) and google play games for online saving. The game will use local save file but if player deletes and reinstalls the game, he should recover his data using Google play games login. Is it possible?

And which one should I use? UserDefault or sqlite?

Thanks in advance.

And let me tag some moderators @slackmoehrle @zhangxm

I need help

The UserDefaults will use key/value pairs - as underlaying framework the SharedPreferences will be used. It’s an XML file and not really fast. It should be mainly used for settings, because the data isn’t changed a lot while using your game.

If you want to save more complex data, I would use SQLite. This is the better solution, in my opinion.

PS: If your Android game supports backup, you don’t need Google Play Games for savegames. Because a reinstall will automatically restore the data (max 25MB). You can read more about it here. Play Games is useful if you want to support multi device gaming. Play on the phone and switch later to a tablet.

1 Like

Thanks. How can I implement SQlite in my cocos2dx game, is there a tutorial on this?

I use SQLite all the time. For everything.