Preferences are also the only way to date to write persistent data when your application is run in the browser.

Obtaining a Preferences instance

Preferences are obtained via the following snippet:

  1. Preferences prefs = Gdx.app.getPreferences("My Preferences");

Note that your application can have multiple preferences, just give them different names.

Writing And Reading Values

Modifying preferences is as simple as modifying a Java Map:

  1. prefs.putString("name", "Donald Duck");String name = prefs.getString("name", "No name stored");prefs.putBoolean("soundOn", true);prefs.putInteger("highscore", 10);

Note that getter methods come in two flavors: with and without a default value. The default value will be returned if there is no value for the specified key in the preferences.

Flushing

flush() method.

  1. // bulk update your preferencesprefs.flush();

Storage

On Windows, Linux, and OS X, preferences are stored in an xml file within the user’s home directory. Gdx.app.getPreferences(). This is useful to know if you want to change or delete them manually for testing. SharedPreferences class is used. This means preferences will survive app updates, but are deleted when the app is uninstalled. javadocs]