Yeah, you can use that now. Nighlies are building. To fetch a Preferences instance do this:
Preferences prefs = Gdx.app.getPreferences("my-preferences");
Note that the name must be useable as a file name. On Android we wrap SharedPreferences. On the desktop we write a Properties XML file to user/preferences-name (“my-preferences” above). That’s not perfect and it’s why we didn’t want to implement that in the first place (Java Preferences are not a solution either…).
Once you have that you can put and get booleans, ints, longs, floats and strings (will be stored as UTF-8).
prefs.putBoolean("bool", true); prefs.putInteger("int", 1234); prefs.putLong("long", Long.MAX_VALUE); prefs.putFloat("float", 1.2345f); prefs.putString("string", "test!"); if(prefs.getBoolean("bool") != true) throw new GdxRuntimeException("bool failed"); if(prefs.getInteger("int") != 1234) throw new GdxRuntimeException("int failed"); if(prefs.getLong("long") != Long.MAX_VALUE) throw new GdxRuntimeException("long failed"); if(prefs.getFloat("float") != 1.2345f) throw new GdxRuntimeException("float failed"); if(!prefs.getString("string").equals("test!")) throw new GdxRuntimeException("string failed");
To make sure your changes are actually persisted you can use
That’s really only relevant on the desktop. If your app terminates due to a severe error the mechanism persisting the thing might not get invoked (no its not a finalizer, but something similar). Flush will immediately persist the current preferences state. So its good practice to call this after you changed your preferences.
That’s it. Enjoy.