# StorageStrategy

# StorageStrategy

Artifact:[androidx.recyclerview:recyclerview-selection](https://developer.android.com/jetpack/androidx/releases/recyclerview)  
[View Source](https://cs.android.com/search?q=file:androidx/recyclerview/selection/StorageStrategy.java+class:androidx.recyclerview.selection.StorageStrategy)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/selection/StorageStrategy "View this page in Java")

<br />

```
abstract class StorageStrategy<K>
```

<br />

*** ** * ** ***

Strategy for storing keys in saved state. Extend this class when using custom key types that aren't supported by default. Prefer use of builtin storage strategies:[createStringStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createStringStorage()),[createLongStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createLongStorage()),[createParcelableStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createParcelableStorage(java.lang.Class<K>)).

See[SelectionTracker.Builder](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/SelectionTracker.Builder)for more detailed advice on which key type to use for your selection keys.  

| Parameters |
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<K>`      | Selection key type. Built in support is provided for String, Long, and Parcelable types. Use the respective factory method to create a StorageStrategy instance appropriate to the desired type.[createStringStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createStringStorage()),[createParcelableStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createParcelableStorage(java.lang.Class<K>)),[createLongStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createLongStorage()) |

## Summary

|                                                                                                                      ### Public constructors                                                                                                                       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#StorageStrategy(java.lang.Class<K>))`(type: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<K!>)` Creates a new instance. |

|                                                                                                  ### Public functions                                                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)                                                                                                                                     | [asBundle](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#asBundle(androidx.recyclerview.selection.Selection<K>))`(selection: `[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection)`<K!>)` Creates a[Bundle](https://developer.android.com/reference/android/os/Bundle.html)from supplied[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection). |
| `abstract `[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection)`<K!>?`                                                                                                 | [asSelection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#asSelection(android.os.Bundle))`(state: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`)` Create a[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection)from supplied[Bundle](https://developer.android.com/reference/android/os/Bundle.html).                                                            |
| `java-static `[StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<`[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`!>`     | [createLongStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createLongStorage())`()`                                                                                                                                                                                                                                                                                                                                                      |
| `java-static `[StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<K!>`                                                                                   | `<K : `[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`?> `[createParcelableStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createParcelableStorage(java.lang.Class<K>))`(type: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<K!>)`                                                                                                                                           |
| `java-static `[StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>` | [createStringStorage](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy#createStringStorage())`()`                                                                                                                                                                                                                                                                                                                                                  |

## Public constructors

### StorageStrategy

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
StorageStrategy(type: Class<K!>)
```

Creates a new instance.  

|                                     Parameters                                      |
|-------------------------------------------------------------------------------------|----------------------------------------|
| `type: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<K!>` | the key type class that is being used. |

## Public functions

### asBundle

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
abstract fun asBundle(selection: Selection<K!>): Bundle
```

Creates a[Bundle](https://developer.android.com/reference/android/os/Bundle.html)from supplied[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection).  

|                                                        Parameters                                                        |
|--------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `selection: `[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection)`<K!>` | The selection to asBundle. |

### asSelection

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
abstract fun asSelection(state: Bundle): Selection<K!>?
```

Create a[Selection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection)from supplied[Bundle](https://developer.android.com/reference/android/os/Bundle.html).  

|                                    Parameters                                     |
|-----------------------------------------------------------------------------------|---------------------------------------------------------------|
| `state: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html) | Bundle instance that may contain parceled Selection instance. |

### createLongStorage

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
java-static fun createLongStorage(): StorageStrategy<Long!>
```  

|                                                                                                Returns                                                                                                |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| [StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<`[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`!>` | StorageStrategy suitable for use with[Long](https://developer.android.com/reference/java/lang/Long.html)keys. |

### createParcelableStorage

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
java-static fun <K : Parcelable?> createParcelableStorage(type: Class<K!>): StorageStrategy<K!>
```  

|                                                         Returns                                                         |
|-------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<K!>` | StorageStrategy suitable for use with[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)keys (like[android.net.Uri](https://developer.android.com/reference/android/net/Uri.html)). |

### createStringStorage

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
java-static fun createStringStorage(): StorageStrategy<String!>
```  

|                                                                                                  Returns                                                                                                  |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| [StorageStrategy](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>` | StorageStrategy suitable for use with[String](https://developer.android.com/reference/java/lang/String.html)keys. |