Interface Preferences
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
void
flush()
Makes sure the preferences are persisted.get()
Returns a read only Map<String, Object> with all the key, objects of the preferences.boolean
getBoolean
(String key) boolean
getBoolean
(String key, boolean defValue) float
float
int
getInteger
(String key) int
getInteger
(String key, int defValue) long
long
putBoolean
(String key, boolean val) putInteger
(String key, int val) void
-
Method Details
-
putBoolean
-
putInteger
-
putLong
-
putFloat
-
putString
-
put
-
getBoolean
-
getInteger
-
getLong
-
getFloat
-
getString
-
getBoolean
-
getInteger
-
getLong
-
getFloat
-
getString
-
get
Returns a read only Map<String, Object> with all the key, objects of the preferences. -
contains
-
clear
void clear() -
remove
-
flush
void flush()Makes sure the preferences are persisted.
-