SharedPreferencesView

public final class SharedPreferencesView


Read-only wrapper around SharedPreferences. This will be passed in to your migration.

Summary

Public methods

final boolean

Checks whether the preferences contains a preference.

final @NonNull Map<@NonNull String, @NonNull Object>

Retrieve all values from the preferences that are in the specified keySet.

final boolean
getBoolean(@NonNull String key, boolean defValue)

Retrieves a boolean value from the preferences.

final float
getFloat(@NonNull String key, float defValue)

Retrieves a float value from the preferences.

final int
getInt(@NonNull String key, int defValue)

Retrieves a int value from the preferences.

final long
getLong(@NonNull String key, long defValue)

Retrieves a long value from the preferences.

final @Nullable String
getString(@NonNull String key, @Nullable String defValue)

Retrieves a string value from the preferences.

final @Nullable Set<@NonNull String>

Retrieves a string set value from the preferences.

Public methods

contains

@NonNull
public final boolean contains(@NonNull String key)

Checks whether the preferences contains a preference.

Parameters
@NonNull String key

the name of the preference to check

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getAll

@NonNull
public final Map<@NonNull String, @NonNull ObjectgetAll()

Retrieve all values from the preferences that are in the specified keySet.

getBoolean

@NonNull
public final boolean getBoolean(@NonNull String key, boolean defValue)

Retrieves a boolean value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

boolean defValue

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getFloat

@NonNull
public final float getFloat(@NonNull String key, float defValue)

Retrieves a float value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

float defValue

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getInt

@NonNull
public final int getInt(@NonNull String key, int defValue)

Retrieves a int value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

int defValue

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getLong

@NonNull
public final long getLong(@NonNull String key, long defValue)

Retrieves a long value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

long defValue

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getString

@Nullable
public final String getString(@NonNull String key, @Nullable String defValue)

Retrieves a string value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

@Nullable String defValue

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration

getStringSet

@Nullable
public final Set<@NonNull StringgetStringSet(@NonNull String key, @Nullable Set<@NonNull String> defValues)

Retrieves a string set value from the preferences.

Parameters
@NonNull String key

the name of the preference to retrieve

@Nullable Set<@NonNull String> defValues

value to return if this preference does not exist

Throws
kotlin.IllegalArgumentException

if key wasn't specified as part of this migration