# 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)

*** ** * ** ***


```
class StorageDomain.Preference : StorageDomain
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.test.backup.host.StorageDomain](https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain) ||
|   | ↳ | [androidx.test.backup.host.StorageDomain.Preference](https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference) |

*** ** * ** ***

Targets on-device SharedPreferences XML files.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#Preference(kotlin.String,kotlin.String,kotlin.Any,kotlin.Boolean)( prefName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, isDeviceProtectedStorage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#hashCode()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#toString()()` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#key()` The specific preference key to seed or verify. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#prefName()` The name of the SharedPreferences XML file (excluding the .xml extension). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | `https://developer.android.com/reference/kotlin/androidx/test/backup/host/StorageDomain.Preference#value()` The value associated with the preference key, or `null` if asserting missing state. |

## Public constructors

### Preference

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

```
Preference(
    prefName: String,
    key: String,
    value: Any? = null,
    isDeviceProtectedStorage: Boolean = false
)
```

## Public functions

### equals

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

```
open fun hashCode(): Int
```

### toString

```
open fun toString(): String
```

## Public properties

### isDeviceProtectedStorage

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

```
val isDeviceProtectedStorage: Boolean
```

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

### key

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

```
val key: String
```

The specific preference key to seed or verify.

### prefName

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

```
val prefName: String
```

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

### value

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

```
val value: Any?
```

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.