# StorageDomain.Preference

Artifact: [androidx.test.backup:backup-host](https://developer.android.com/jetpack/androidx/releases/test-backup) [View Source](https://cs.android.com/search?q=file:androidx/test/backup/host/StorageDomain.kt+class:androidx.test.backup.host.StorageDomain.Preference) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

*** ** * ** ***


```
public final class StorageDomain.Preference extends StorageDomain
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.test.backup.host.StorageDomain](https://developer.android.com/reference/androidx/test/backup/host/StorageDomain) ||
|   | ↳ | [androidx.test.backup.host.StorageDomain.Preference](https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference) |

*** ** * ** ***

Targets on-device SharedPreferences XML files.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#Preference(kotlin.String,kotlin.String,kotlin.Any,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html prefName, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html key, https://developer.android.com/reference/java/lang/Object.html value, boolean isDeviceProtectedStorage )` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#getKey()()` The specific preference key to seed or verify. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#getPrefName()()` The name of the SharedPreferences XML file (excluding the .xml extension). |
| `final https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#getValue()()` The value associated with the preference key, or `null` if asserting missing state. |
| `int` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#hashCode()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#isDeviceProtectedStorage()()` Whether the SharedPreferences file is in device-protected storage, which is available before the user first unlocks the device, rather than in the default storage of the app. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/backup/host/StorageDomain.Preference#toString()()` |

## Public constructors

### Preference

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

```
public Preference(
    @NonNull String prefName,
    @NonNull String key,
    Object value,
    boolean isDeviceProtectedStorage
)
```

## Public methods

### equals

```
public boolean equals(Object other)
```

### getKey

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

```
public final @NonNull String getKey()
```

The specific preference key to seed or verify.

### getPrefName

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

```
public final @NonNull String getPrefName()
```

The name of the SharedPreferences XML file (excluding the .xml extension).

### getValue

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

```
public final Object getValue()
```

The value associated with the preference key, or `null` if asserting missing state. Supported types are: String, Int, Long, Float, Boolean, a Set of Strings, or null; other types fail construction with an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`. A set is stored with `putStringSet` and compared regardless of the order of its elements; the preference keeps a copy of it. A `null` value is seeded by removing the key and verified by checking that the key is absent. Clearing app data also removes the key, so a `null` value cannot detect a restore that loses data.

### hashCode

```
public int hashCode()
```

### isDeviceProtectedStorage

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

```
public final boolean isDeviceProtectedStorage()
```

Whether the SharedPreferences file is in device-protected storage, which is available before the user first unlocks the device, rather than in the default storage of the app. That is credential-encrypted storage, unless the app sets `android:defaultToDeviceProtectedStorage`.

### toString

```
public @NonNull String toString()
```