APIdia Launch Partner
Top Description Methods
com.badlogic.gdx

public Interface Preferences

Imports
java.util.Map

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.

Author
mzechner

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
public void
flush()

Makes sure the preferences are persisted.

public Map<String, ?>
get()

Returns a read only Map<string, object> with all the key, objects of the preferences.

public boolean
public boolean
getBoolean(String key, boolean defValue)

public float
public float
getFloat(String key, float defValue)

public int
public int
getInteger(String key, int defValue)

public long
public long
getLong(String key, long defValue)

public String
public String
getString(String key, String defValue)

public Preferences
put(Map<String, ?> vals)

public Preferences
putBoolean(String key, boolean val)

public Preferences
putFloat(String key, float val)

public Preferences
putInteger(String key, int val)

public Preferences
putLong(String key, long val)

public Preferences
public void

Method Detail

clearback to summary
public void clear()
containsback to summary
public boolean contains(String key)
flushback to summary
public void flush()

Makes sure the preferences are persisted.

getback to summary
public Map<String, ?> get()

Returns a read only Map with all the key, objects of the preferences.

getBooleanback to summary
public boolean getBoolean(String key)
getBooleanback to summary
public boolean getBoolean(String key, boolean defValue)
getFloatback to summary
public float getFloat(String key)
getFloatback to summary
public float getFloat(String key, float defValue)
getIntegerback to summary
public int getInteger(String key)
getIntegerback to summary
public int getInteger(String key, int defValue)
getLongback to summary
public long getLong(String key)
getLongback to summary
public long getLong(String key, long defValue)
getStringback to summary
public String getString(String key)
getStringback to summary
public String getString(String key, String defValue)
putback to summary
public Preferences put(Map<String, ?> vals)
putBooleanback to summary
public Preferences putBoolean(String key, boolean val)
putFloatback to summary
public Preferences putFloat(String key, float val)
putIntegerback to summary
public Preferences putInteger(String key, int val)
putLongback to summary
public Preferences putLong(String key, long val)
putStringback to summary
public Preferences putString(String key, String val)
removeback to summary
public void remove(String key)