SharedPrefsUtils

class SharedPrefsUtils(context: Context, prefName: String)

Deprecated

SharedPreferences is deprecated because of its performance. Please use DataStore instead.

Replace with

import com.bluewhaleyt.common.datasaving.utils.DataStoreUtils

This utility aims to simplify the usage of SharedPreferences.

For Kotlin, using DataStore instead is highly recommended, please refer DataStore.

See also

Constructors

Link copied to clipboard
constructor(context: Context, prefName: String)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun clear()

Clears all values from this SharedPreferences.

Link copied to clipboard
fun <T : Any> get(key: String, defaultValue: T): T

Retrieves the value associated with the given key from SharedPreferences. If the key is not found, the default value is returned.

Link copied to clipboard

Returns true if the specified key is marked as one-time only in the SharedPreferences.

Link copied to clipboard

Returns a list of keys for all preferences stored in the app.

Link copied to clipboard
fun remove(key: String?)

Removes the entry for the specified key from this SharedPreferences.

Link copied to clipboard
fun write(key: String, value: Any, oneTimeOnly: Boolean = false)

Writes a key-value pair to the SharedPreferences.