Package 

Class CTPreference

  • All Implemented Interfaces:
    com.clevertap.android.sdk.store.preference.ICTPreference

    @RestrictTo(value = {RestrictTo.Scope.LIBRARY_GROUP}) 
    public final class CTPreference
     implements ICTPreference
                        

    The CTPreference class implements the ICTPreference interface 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 Detail

      • CTPreference

        CTPreference(Context context, String prefName)
        Parameters:
        context - The Android application context.
        prefName - The name of the shared preferences file.
    • 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.
      • readAll

         Map<String, ?> readAll()

        Reads all key-value pairs from the shared preferences.

      • 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.
      • isEmpty

         Boolean isEmpty()

        Checks if the shared preferences are empty.

      • size

         Integer size()

        Gets the size (number of key-value pairs) of the shared preferences.

      • 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.