# savedstatehandle

Published articles for savedstatehandle.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Input validation in Jetpack Compose

DevFeed: [Input validation in Jetpack Compose](<https://devfeed.tech/articles/input-validation-in-jetpack-compose-25897.md>)

Original publisher: [Read original article](<https://proandroiddev.com/input-validation-in-jetpack-compose-e99c18b44fe3?source=rss-56174fa84bcc------2>)

Author: Denys Rudenko

Published: 2021-08-22T16:42:02Z

Content type: tutorial

Language: en

Sources: [Stories by Denis Rudenko on Medium](<https://devfeed.tech/sources/stories-by-denis-rudenko-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [User experience (UX)](<https://devfeed.tech/topics/ux.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [androiddevweekly](<https://devfeed.tech/tags/androiddevweekly.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [savedstatehandle](<https://devfeed.tech/tags/savedstatehandle.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [ux](<https://devfeed.tech/tags/ux.md>), [validation](<https://devfeed.tech/tags/validation.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This tutorial demonstrates manual and automatic input validation in Jetpack Compose. It uses composables, ViewModels, Dagger Hilt, StateFlow, and savedStateHandle to preserve input state after process death, validate fields, control button state, and emit success or error events. It also discusses restoring focus and improving keyboard-related user experience.

### Source excerpt

This post will not only focus on manual & auto validation of TextField inputs, but also on how to provide a nice UX by handling process death, including highlighting the last focused field upon restoration. https://medium.com/media/7d776a0ec6ff89810e194adf54680973/hrefSetup We'll use composables, viewModels & Dagger Hilt in these samples. Part 1: InputWrapper Let's create a wrapper for inputs, so it can contain both input value and errorId, if there is a validation error. Class is parcelable, so we can save it inside savedStateHandle later. https://medium.com/media/6c74ba5b4f958d63646a819643b45620/hrefPart 2: ViewModel (simplified version)https://medium.com/media/39bf975a63461cd00f68b8360c6a8f6b/href We're getting a stateFlow from the savedStateHandle using .getStateFlow extension. Using savedStateHandle here allows us to retain the latest data after process death happens. You can also use getLiveData, it's a matter of personal preferences unless you plan to perform observable.switchMap/flatMapLatest type of operations, since there is a subtle difference between stateFlow & liveData in such scenarios described here & change proposal created. areInputsValid stateFlow is combining name & creditCardNumber flows into a single one. The results it returns depend on whether input fields are valid or not. It's invoked whenever there is new emition to name or creditCardNumber flows. We'll use it's value to control buttons enabled/disabled state in our composable. _events will be used for one time events emission to the view layer. ScreenEvent is a sealed class representing all of our one time events. onNameEntered & onCardNumberEntered will be invoked when user enters symbols inside the TextField. We find out whether the input is valid by using an InputValidator object. It's returning either a string resource id containing error message, or a null. Latter means that input is valid. We store the new value & errorId using: https://medium.com/media/d9ad9c61328481f3318c143e6daf3

## Building Reactive UIs with LiveData and SavedStateHandle (or equivalent approaches)

DevFeed: [Building Reactive UIs with LiveData and SavedStateHandle (or equivalent approaches)](<https://devfeed.tech/articles/building-reactive-uis-with-livedata-and-savedstatehandle-or-equivalent-approaches-25928.md>)

Original publisher: [Read original article](<https://itnext.io/building-reactive-uis-with-livedata-and-savedstatehandle-or-equivalent-approaches-4e934487035f?source=rss-7a8d96da8cb6------2>)

Author: Gabor Varadi

Published: 2020-10-04T19:53:05Z

Content type: tutorial

Language: en

Sources: [Stories by Gabor Varadi on Medium](<https://devfeed.tech/sources/stories-by-gabor-varadi-on-medium.md>)

Topics: [reactive](<https://devfeed.tech/topics/reactive.md>), [Android](<https://devfeed.tech/topics/android.md>), [Jetpack](<https://devfeed.tech/topics/jetpack.md>), [RxJava](<https://devfeed.tech/topics/rxjava.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [observable](<https://devfeed.tech/tags/observable.md>), [reactive](<https://devfeed.tech/tags/reactive.md>), [reactive-programming](<https://devfeed.tech/tags/reactive-programming.md>), [room](<https://devfeed.tech/tags/room.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>), [savedstatehandle](<https://devfeed.tech/tags/savedstatehandle.md>)

### AI overview

This article explains LiveData as a reactive, observable, lifecycle-aware data holder for Android applications. It argues that LiveData remains useful alongside RxJava and Kotlin coroutines because its lifecycle activation states allow it to represent reactive data sources, including Room-backed data that refreshes after invalidation.

### Source excerpt

Building Reactive UIs with LiveData and SavedStateHandle (or equivalent approaches like Rx) You can also follow the related discussion thread on /r/android_devs. LiveData is a misunderstood beast. Every so often, you see comments like "LiveData does not belong in Repositories", or that with the existence of RxJava, Coroutine Channels, or Coroutine Flows -- there's "no reason to use LiveData at all". While there are components in these libraries that have overlapping responsibilities (BehaviorRelay, ConflatedBroadcastChannel, MutableStateFlow), that doesn't mean LiveData is useless. With the relatively new additions to Jetpack, such as the liveData { coroutine builder, LiveData is actually quite interesting. What is LiveData? If you try to find a definition for LiveData, you'll find that it's a "reactive, observable, lifecycle-aware data holder". We know it can be observed, and we know it holds 1 data value that is re-emitted for any new observer (and any changes made to it are also emitted), just like any BehaviorRelay. But what makes it special? Due to LiveData's lifecycle-awareness, it comes with its own "activation state" ( onActive and onInactive). It lets you know when there is an active observer, and when there are no longer any active observers. The trick is that this makes it far more than "just an every-day data holder". This allows LiveData to represent reactive datasources. I'd even wager that this is the original purpose for which LiveData was created, if Room's ComputableLiveData is any indication (as that also relies on onActive to trigger the refresh of the query results, if the table had been invalidated by a write to it). Why do I want reactive datasources? If you have data or state that can change over time, it's significantly easier to be notified of changes, than it is to poll for possible changes (and potentially miss out on changes if we tried to fetch data at the wrong time). This means that by using an "observer" (or change listener), we can r