Interface Preferences


public 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 Details

    • putBoolean

      Preferences putBoolean(String key, boolean val)
    • putInteger

      Preferences putInteger(String key, int val)
    • putLong

      Preferences putLong(String key, long val)
    • putFloat

      Preferences putFloat(String key, float val)
    • putString

      Preferences putString(String key, String val)
    • put

      Preferences put(Map<String,?> vals)
    • getBoolean

      boolean getBoolean(String key)
    • getInteger

      int getInteger(String key)
    • getLong

      long getLong(String key)
    • getFloat

      float getFloat(String key)
    • getString

      String getString(String key)
    • getBoolean

      boolean getBoolean(String key, boolean defValue)
    • getInteger

      int getInteger(String key, int defValue)
    • getLong

      long getLong(String key, long defValue)
    • getFloat

      float getFloat(String key, float defValue)
    • getString

      String getString(String key, String defValue)
    • get

      Map<String,?> get()
      Returns a read only Map<String, Object> with all the key, objects of the preferences.
    • contains

      boolean contains(String key)
    • clear

      void clear()
    • remove

      void remove(String key)
    • flush

      void flush()
      Makes sure the preferences are persisted.