-
- All Implemented Interfaces:
-
com.clevertap.android.sdk.store.preference.ICTPreference
@RestrictTo(value = {RestrictTo.Scope.LIBRARY_GROUP}) public final class CTPreference implements ICTPreference
The
CTPreferenceclass implements theICTPreferenceinterface and provides methods to read and write various types of data to shared preferences. It ensures safe handling of shared preferences operations in a weakly referenced context to prevent memory leaks.
-
-
Constructor Summary
Constructors Constructor Description CTPreference(Context context, String prefName)
-
Method Summary
Modifier and Type Method Description StringreadString(String key, String default)Reads a string from the shared preferences. BooleanreadBoolean(String key, Boolean default)Reads a boolean from the shared preferences. IntegerreadInt(String key, Integer default)Reads an integer from the shared preferences. LongreadLong(String key, Long default)Reads a long from the shared preferences. FloatreadFloat(String key, Float default)Reads a float from the shared preferences. Set<String>readStringSet(String key, Set<String> default)Reads a string set from the shared preferences. Map<String, ?>readAll()Reads all key-value pairs from the shared preferences. UnitwriteString(String key, String value)Writes a string to the shared preferences. UnitwriteStringImmediate(String key, String value)Writes a string to the shared preferences immediately (without applying changes asynchronously). UnitwriteBoolean(String key, Boolean value)Writes a boolean to the shared preferences. UnitwriteBooleanImmediate(String key, Boolean value)Writes a boolean to the shared preferences immediately (without applying changes asynchronously). UnitwriteInt(String key, Integer value)Writes an integer to the shared preferences. UnitwriteIntImmediate(String key, Integer value)Writes an integer to the shared preferences immediately (without applying changes asynchronously). UnitwriteLong(String key, Long value)Writes a long to the shared preferences. UnitwriteLongImmediate(String key, Long value)Writes a long to the shared preferences immediately (without applying changes asynchronously). UnitwriteFloat(String key, Float value)Writes a float to the shared preferences. UnitwriteFloatImmediate(String key, Float value)Writes a float to the shared preferences immediately (without applying changes asynchronously). UnitwriteStringSet(String key, Set<String> value)Writes a string set to the shared preferences. UnitwriteStringSetImmediate(String key, Set<String> value)Writes a string set to the shared preferences immediately (without applying changes asynchronously). UnitwriteMap(String key, Map<String, ?> value)Writes a map to the shared preferences. UnitwriteMapImmediate(String key, Map<String, ?> value)Writes a map to the shared preferences immediately (without applying changes asynchronously). BooleanisEmpty()Checks if the shared preferences are empty. Integersize()Gets the size (number of key-value pairs) of the shared preferences. Unitremove(String key)Removes a key and its associated value from the shared preferences. UnitremoveImmediate(String key)Removes a key and its associated value from the shared preferences immediately (without applying changes asynchronously). UnitchangePreferenceName(String prefName)Changes the name of the shared preferences. -
-
Method Detail
-
readString
String readString(String key, String default)
Reads a string from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
readBoolean
Boolean readBoolean(String key, Boolean default)
Reads a boolean from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
readInt
Integer readInt(String key, Integer default)
Reads an integer from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
readLong
Long readLong(String key, Long default)
Reads a long from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
readFloat
Float readFloat(String key, Float default)
Reads a float from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
readStringSet
Set<String> readStringSet(String key, Set<String> default)
Reads a string set from the shared preferences.
- Parameters:
key- The key associated with the value.default- The default value to return if the key is not present.
-
writeString
Unit writeString(String key, String value)
Writes a string to the shared preferences.
- Parameters:
key- The key associated with the value.value- The string value to be stored.
-
writeStringImmediate
@WorkerThread() Unit writeStringImmediate(String key, String value)
Writes a string to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The string value to be stored.
-
writeBoolean
Unit writeBoolean(String key, Boolean value)
Writes a boolean to the shared preferences.
- Parameters:
key- The key associated with the value.value- The boolean value to be stored.
-
writeBooleanImmediate
@WorkerThread() Unit writeBooleanImmediate(String key, Boolean value)
Writes a boolean to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The boolean value to be stored.
-
writeInt
Unit writeInt(String key, Integer value)
Writes an integer to the shared preferences.
- Parameters:
key- The key associated with the value.value- The integer value to be stored.
-
writeIntImmediate
@WorkerThread() Unit writeIntImmediate(String key, Integer value)
Writes an integer to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The integer value to be stored.
-
writeLong
Unit writeLong(String key, Long value)
Writes a long to the shared preferences.
- Parameters:
key- The key associated with the value.value- The long value to be stored.
-
writeLongImmediate
@WorkerThread() Unit writeLongImmediate(String key, Long value)
Writes a long to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The long value to be stored.
-
writeFloat
Unit writeFloat(String key, Float value)
Writes a float to the shared preferences.
- Parameters:
key- The key associated with the value.value- The float value to be stored.
-
writeFloatImmediate
@WorkerThread() Unit writeFloatImmediate(String key, Float value)
Writes a float to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The float value to be stored.
-
writeStringSet
Unit writeStringSet(String key, Set<String> value)
Writes a string set to the shared preferences.
- Parameters:
key- The key associated with the value.value- The string set value to be stored.
-
writeStringSetImmediate
@WorkerThread() Unit writeStringSetImmediate(String key, Set<String> value)
Writes a string set to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The string set value to be stored.
-
writeMap
Unit writeMap(String key, Map<String, ?> value)
Writes a map to the shared preferences.
- Parameters:
key- The key associated with the value.value- The map value to be stored.
-
writeMapImmediate
@WorkerThread() Unit writeMapImmediate(String key, Map<String, ?> value)
Writes a map to the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key associated with the value.value- The map value to be stored.
-
remove
Unit remove(String key)
Removes a key and its associated value from the shared preferences.
- Parameters:
key- The key to be removed.
-
removeImmediate
@WorkerThread() Unit removeImmediate(String key)
Removes a key and its associated value from the shared preferences immediately (without applying changes asynchronously).
- Parameters:
key- The key to be removed.
-
changePreferenceName
Unit changePreferenceName(String prefName)
Changes the name of the shared preferences.
- Parameters:
prefName- The new name for the shared preferences.
-
-
-
-