A Preference instance is a hash map holding different values. It is stored alongside your application (SharedPreferences on Android, LocalStorage on GWT, on the desktop a Java Preferences file in a ".prefs" directory will be created, and on iOS an NSMutableDictionary will be written to the given file).
Caution
On the desktop platform, all libGDX applications share the same ".prefs" directory. To avoid collisions use specific names like "com.myname.game1.settings" instead of "settings".
To persist changes made to a preferences instance flush() has to be invoked. With the exception of Android, changes
are cached in memory prior to flushing. On iOS changes are not synchronized between different preferences instances.
Use Application#getPreferences(String) to look up a specific preferences instance. Note that on several backends the
preferences name will be used as the filename, so make sure the name is valid for a filename.
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | |
| public void | |
| public Map | |
| public boolean | |
| public boolean | |
| public float | |
| public float | |
| public int | |
| public int | |
| public long | |
| public long | |
| public String | |
| public String | |
| public Preferences | |
| public Preferences | |
| public Preferences | |
| public Preferences | |
| public Preferences | |
| public Preferences | |
| public void |
| clear | back to summary |
|---|---|
| public void clear() | |
| contains | back to summary |
|---|---|
| public boolean contains(String key) | |
| flush | back to summary |
|---|---|
| public void flush() Makes sure the preferences are persisted. | |
| get | back to summary |
|---|---|
| public Map Returns a read only Map | |
| getBoolean | back to summary |
|---|---|
| public boolean getBoolean(String key) | |
| getBoolean | back to summary |
|---|---|
| public boolean getBoolean(String key, boolean defValue) | |
| getFloat | back to summary |
|---|---|
| public float getFloat(String key) | |
| getFloat | back to summary |
|---|---|
| public float getFloat(String key, float defValue) | |
| getInteger | back to summary |
|---|---|
| public int getInteger(String key) | |
| getInteger | back to summary |
|---|---|
| public int getInteger(String key, int defValue) | |
| getLong | back to summary |
|---|---|
| public long getLong(String key) | |
| getLong | back to summary |
|---|---|
| public long getLong(String key, long defValue) | |
| getString | back to summary |
|---|---|
| public String getString(String key) | |
| getString | back to summary |
|---|---|
| public String getString(String key, String defValue) | |
| put | back to summary |
|---|---|
| public Preferences put(Map<String, ?> vals) | |
| putBoolean | back to summary |
|---|---|
| public Preferences putBoolean(String key, boolean val) | |
| putFloat | back to summary |
|---|---|
| public Preferences putFloat(String key, float val) | |
| putInteger | back to summary |
|---|---|
| public Preferences putInteger(String key, int val) | |
| putLong | back to summary |
|---|---|
| public Preferences putLong(String key, long val) | |
| putString | back to summary |
|---|---|
| public Preferences putString(String key, String val) | |
| remove | back to summary |
|---|---|
| public void remove(String key) | |