# RecyclerView.Adapter.StateRestorationPolicy

# RecyclerView.Adapter.StateRestorationPolicy

Artifact:[androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview)  
[View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/RecyclerView.java+class:androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)  
Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.2.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy "View this page in Java")

<br />

```
enum RecyclerView.Adapter.StateRestorationPolicy
```

<br />

*** ** * ** ***

Defines how this Adapter wants to restore its state after a view reconstruction (e.g. configuration change).

## Summary

|                                                                         ### Enum Values                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW)                           | Adapter is ready to restore State immediately, RecyclerView will provide the state to the LayoutManager in the next layout pass.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [PREVENT](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT)                       | RecyclerView will not restore the state for the Adapter until a call to[setStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy))is made with either[ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW)or[PREVENT_WHEN_EMPTY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY). |
| [PREVENT_WHEN_EMPTY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY) | Adapter is ready to restore State when it has more than 0 items.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |

|                                                                                                                            ### Public functions                                                                                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy)`!`                                                                                     | [valueOf](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#valueOf(java.lang.String))`(name: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Returns the enum constant of this type with the specified name. |
| `java-static `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy)`!>!` | [values](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#values())`()` Returns an array containing the constants of this enum type, in the order they're declared.                                                                                 |

## Enum Values

### ALLOW

```
val RecyclerView.Adapter.StateRestorationPolicy.ALLOW: RecyclerView.Adapter.StateRestorationPolicy
```

Adapter is ready to restore State immediately, RecyclerView will provide the state to the LayoutManager in the next layout pass.  

### PREVENT

```
val RecyclerView.Adapter.StateRestorationPolicy.PREVENT: RecyclerView.Adapter.StateRestorationPolicy
```

RecyclerView will not restore the state for the Adapter until a call to[setStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy))is made with either[ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW)or[PREVENT_WHEN_EMPTY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY).  

### PREVENT_WHEN_EMPTY

```
val RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY: RecyclerView.Adapter.StateRestorationPolicy
```

Adapter is ready to restore State when it has more than 0 items. RecyclerView will provide the state to the LayoutManager as soon as the Adapter has 1 or more items.  

## Public functions

### valueOf

Added in 1.2.0  

```
java-static fun valueOf(name: String!): RecyclerView.Adapter.StateRestorationPolicy!
```

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)  

|                                                                                  Returns                                                                                  |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
| [RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy)`!` | the enum constant with the specified name |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if this enum type has no constant with the specified name |

### values

Added in 1.2.0  

```
java-static fun values(): Array<RecyclerView.Adapter.StateRestorationPolicy!>!
```

Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants.  

|                                                                                                                            Returns                                                                                                                            |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy)`!>!` | an array containing the constants of this enum type, in the order they're declared |