set

operator fun Preferences.set(key: String, value: String): Preferences

Stores a String under the given key in the Preferences.


operator fun Preferences.set(key: String, value: Boolean): Preferences

Stores a Boolean under the given key in the Preferences.


operator fun Preferences.set(key: String, value: Int): Preferences

Stores an Int under the given key in the Preferences.


operator fun Preferences.set(key: String, value: Long): Preferences

Stores a Long under the given key in the Preferences.


operator fun Preferences.set(key: String, value: Float): Preferences

Stores a Float under the given key in the Preferences.


operator fun Preferences.set(key: String, value: Any): Preferences

Serializes any value as a JSON string and stores it under the given key in the Preferences. Note that value must be JSON-serializable - see the Json module for details.

A new Json instance is created for each serialized value. If the preference is saved frequently and excessive object creation might be a concern, consider manual serialization and storing the value as a String.


fun Preferences.set(pair: Pair<String, Any>): Preferences

Stores any value under the given key in the Preferences. The first value of the pair is considered the key, while the second is treated as the value.

If the value is not of String, Boolean, Int, Float, Double or Long type, then it will be serialized and stored as a JSON string using the Json module.

A new Json instance is created for each serialized value. If the preference is saved frequently and excessive object creation might be a concern, consider manual serialization and storing the value as a String.

Note that Double values are stored as Float, since Preferences do not support doubles. Please add explicit cast to Float when storing Double values or wrap with a JSON-serializable object. This method throws GdxRuntimeException if the value is a Double outside of the Float range.


operator fun Preferences.set(key: String, value: Double): Preferences

Deprecated

Doubles are not supported by libGDX Preferences. Value will be stored as Float instead. Please add explicit cast.

Replace with

set(key, value.toFloat()

Stores a Double as Float under the given key in the Preferences. Throws GdxRuntimeException if value is outside the Float range.