# Crash course on the Android UI layer | Part 2

DevFeed: [Crash course on the Android UI layer | Part 2](<https://devfeed.tech/articles/crash-course-on-the-android-ui-layer-part-2-22599.md>)

Original publisher: [Read original article](<https://medium.com/bumble-tech/crash-course-on-the-android-ui-layer-part-2-2335171467e0?source=rss----6353b5325b1a---4>)

Author: Manuel Vivo

Published: 2023-12-19T15:58:45Z

Content type: article

Language: en

Sources: [Bumble Tech](<https://devfeed.tech/sources/bumble-tech.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [User Interfaces](<https://devfeed.tech/topics/user-interfaces.md>), [Jetpack](<https://devfeed.tech/topics/jetpack.md>), [business logic](<https://devfeed.tech/topics/business-logic.md>), [Stateful](<https://devfeed.tech/topics/stateful.md>), [Large Screen](<https://devfeed.tech/topics/large-screen.md>), [parcelable](<https://devfeed.tech/topics/parcelable.md>)

Tags: [2023](<https://devfeed.tech/tags/2023.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [apis](<https://devfeed.tech/tags/apis.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [best-practices](<https://devfeed.tech/tags/best-practices.md>), [blog](<https://devfeed.tech/tags/blog.md>), [blog-post](<https://devfeed.tech/tags/blog-post.md>), [business-logic](<https://devfeed.tech/tags/business-logic.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [decision-trees](<https://devfeed.tech/tags/decision-trees.md>), [droidcon](<https://devfeed.tech/tags/droidcon.md>), [format](<https://devfeed.tech/tags/format.md>), [logic](<https://devfeed.tech/tags/logic.md>), [save](<https://devfeed.tech/tags/save.md>), [saving](<https://devfeed.tech/tags/saving.md>), [series](<https://devfeed.tech/tags/series.md>), [state](<https://devfeed.tech/tags/state.md>), [talk](<https://devfeed.tech/tags/talk.md>), [types](<https://devfeed.tech/tags/types.md>), [ui](<https://devfeed.tech/tags/ui.md>), [video](<https://devfeed.tech/tags/video.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

## AI overview

State placement depends on what uses it and how long it must survive. Keep business logic and screen UI state in a screen-level state holder, usually `androidX.ViewModel`, which survives configuration changes and can keep `viewModelScope` work running while it remains in memory. Keep simple UI logic in the UI; move growing or reusable UI logic into a plain state holder scoped to the UI, which may hold lifecycle references. Hoist state to the lowest common ancestor that reads or writes it, except state needed by business logic, which belongs in the screen-level holder. SavedState APIs preserve transient UI state through configuration changes and system-initiated process death; persistent storage is for application data and can survive app dismissal. The excerpt also cautions that long-running ViewModel work may suit WorkManager better and testing `viewModelScope` requires replacing `MainDispatcher`.

## Source excerpt

Crash Course on the Android UI Layer | Part 2State Holders and Saving State This blog post series aims to summarise the Android Developer guidance on the UI layer. We'll explore all the entities involved in it, understand the role each part plays, and discuss best practices. By the end of this series, you will have a general understanding of what happens on the UI layer and how to best handle state and logic within it, the various APIs involved, and how to use them. Additionally, we'll provide decision trees to assist you when you're in doubt. In part 1, we covered the UI and the UI state. You should already know the different entities present on the UI layer, and how to think about the UI and UI state effectively. Crash course on the Android UI layer | Part 1 Now it's time for Part 2! We'll cover state holders and other UI layer-related topics such as where to hoist state and save UI state on Android. If you prefer to consume this content in video format, check out the talk I delivered at Droidcon London 2023: Peeling Back the Layers: Unmasking the UI-nknown! State holders State holders simplify the UI by handling logic and/or exposing UI state. In this section, we'll see how to implement state holders and the implementation details to consider. To determine the implementation details, we first need to identify the types of logic commonly found in an Android app. Types of logic We have already discussed that business logic involves implementing the product requirements that specify how application data is created, stored, and modified. When business logic is present in the UI layer, it's recommended to manage this logic at the screen level. We'll see more of this later. Another type of logic is the UI logic. UI logic determines how to display state changes on the screen. While business logic dictates what to do with data, UI logic determines how to visually display it. The UI logic is dependent on the UI configuration. For instance, in a typical app, displaying a d