chetan-garg36.medium.com 8 min read Original Source

Is ViewModel Dead? AppState Is Coming

Google shipped two alpha libraries under the name AppState, and the guide shows Compose State running in repositories, services and widgets. I read every page of it to find out whether your ViewModels are next, and how the two compare.

Free link here for non-members. Paid members, please skip the free link and read till the end on Medium. If you enjoyed it, clap and share!

On October 28, 2026, a new row showed up in the AndroidX release table: appstate.transform and appstate.statestore, both at 1.0.0-alpha01.

Drop that link in any Android team chat and I can guess the first reply: “So ViewModel is dead?” The second one: “Finally, app-level state that isn’t a god singleton.”

You can blame the name for that. “AppState” sounds like something that sits above your screens and replaces whatever holds screen state today.

I treated that question like a case to crack. Is ViewModel dead, or did the name oversell it? I read the main page, the two library pages, the “Use Compose State outside the UI” page and both release notes, and I collected clues as I went. The answer surprised me, and it’s not the one the name suggests. Let’s get there the same way I did.

🧩 The suspect: two libraries called AppState

AppState is a group of two libraries built on the Compose runtime, not on Compose UI:

  • Transform runs a @Composable block without any UI and turns whatever it reads into a Compose State.
  • StateStore is a type-safe container that stores shared app state and exposes it as Compose State.

The artifacts are androidx.appstate.transform:transform, androidx.appstate.transform:transform-testing, androidx.appstate.statestore:statestore and androidx.appstate.statestore:statestore-datastore. The release pages also list desktop, iOS, wasm and other targets for both libraries, so this is multiplatform from day one. As a KMP person, that part made me smile.

Both libraries rest on one idea: Compose State is a value holder backed by the snapshot system, and the snapshot system has no dependency on drawing pixels. The guide lists two benefits of using it beyond the UI. Dependency tracking is automatic and dynamic, so Compose doesn’t observe a branch you didn’t take. And you can update several MutableState properties atomically with Snapshot.withMutableSnapshot, instead of choosing between one giant StateFlow<UiState> and several flows that can’t change together.

Takeaway: AppState answers where Compose State can live. It adds no new kind of screen.

🎓 Want to put coroutines to work on something fun? My Udemy course Build Generative AI App Jetpack Compose, Langchain4j &Ollama builds six local-LLM apps entirely in Kotlin, from a Hello World AI to a RAG app over Medium articles.

🐛 Clue 1: Transform shows up inside a ViewModel

The first thing that didn’t fit the “ViewModel is dead” theory: the guide’s main Transform example lives inside a ViewModel. I rewrote it for a flight search screen:

<button data-code="@HiltViewModel
class FlightSearchViewModel @Inject constructor(
private val flightsRepository: FlightsRepository,
private val networkMonitor: NetworkMonitor,
savedStateHandle: SavedStateHandle,
) : ViewModel() {
var selectedFlightIds by mutableStateOf(emptySet())
private set
var query by savedStateHandle.saveable { mutableStateOf("") }
private set
fun updateQuery(newQuery: String) {
Snapshot.withMutableSnapshot {
query = newQuery
selectedFlightIds = emptySet()
}
}
val uiState: State = transform(
initialValue = SearchUiState.Loading,
scope = viewModelScope,
) {
val flights = remember(query) {
flightsRepository.search(query)
}.collectAsState(initial = null).value
?: return@transform SearchUiState.Loading
SearchUiState.Success(
flights = flights,
selectedIds = selectedFlightIds,
isOnline = networkMonitor.isOnline.value,
)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

@HiltViewModel
class FlightSearchViewModel @Inject constructor(
    private val flightsRepository: FlightsRepository,
    private val networkMonitor: NetworkMonitor,
    savedStateHandle: SavedStateHandle,
) : ViewModel() {
    var selectedFlightIds by mutableStateOf(emptySet<String>())
        private set
    var query by savedStateHandle.saveable { mutableStateOf("") }
        private set
    fun updateQuery(newQuery: String) {
        Snapshot.withMutableSnapshot {
            query = newQuery
            selectedFlightIds = emptySet()
        }
    }
    val uiState: State<SearchUiState> = transform<SearchUiState>(
        initialValue = SearchUiState.Loading,
        scope = viewModelScope,
    ) {
        val flights = remember(query) {
            flightsRepository.search(query)
        }.collectAsState(initial = null).value
            ?: return@transform SearchUiState.Loading
        SearchUiState.Success(
            flights = flights,
            selectedIds = selectedFlightIds,
            isOnline = networkMonitor.isOnline.value,
        )
    }
}
@HiltViewModel
class FlightSearchViewModel @Inject constructor(
    private val flightsRepository: FlightsRepository,
    private val networkMonitor: NetworkMonitor,
    savedStateHandle: SavedStateHandle,
) : ViewModel() {
    var selectedFlightIds by mutableStateOf(emptySet<String>())
        private set
    var query by savedStateHandle.saveable { mutableStateOf("") }
        private set
    fun updateQuery(newQuery: String) {
        Snapshot.withMutableSnapshot {
            query = newQuery
            selectedFlightIds = emptySet()
        }
    }
    val uiState: State<SearchUiState> = transform<SearchUiState>(
        initialValue = SearchUiState.Loading,
        scope = viewModelScope,
    ) {
        val flights = remember(query) {
            flightsRepository.search(query)
        }.collectAsState(initial = null).value
            ?: return@transform SearchUiState.Loading
        SearchUiState.Success(
            flights = flights,
            selectedIds = selectedFlightIds,
            isOnline = networkMonitor.isOnline.value,
        )
    }
}

Read it twice and look for combine, flatMapLatest or stateIn. You won’t find any of them. The block reads query, selectedFlightIds, a repository Flow and the network state, and any change re-runs it. remember(query) keeps the database Flow alive when only the selection changes, so the query doesn’t restart. SavedStateHandle.saveable makes query survive process death as a real MutableState. The guide warns against the bare SavedStateHandle.saved delegate here, because it returns a plain property that the block can’t track.

The ViewModel still does a ViewModel’s job: the transform lives as long as viewModelScope, and Transform took over the Flow plumbing and nothing more.

I’d underline one detail from a note in the guide twice. A transform scoped to viewModelScope stays active for the whole life of that scope, including while the UI is in the background. The @Composable overload of transform follows the composition that calls it instead.

Takeaway: Transform is a new way to produce state. The ViewModel still owns it.

🐛 Clue 2: StateStore is for state no screen owns

StateStore is the part that does feel like “app state”, and the closest thing the prosecution has to evidence. Say you hold a seat for ten minutes during checkout. The booking screen shows a countdown, a home screen widget shows it too, and a service needs to release the hold when it expires. Which ViewModel owns that? None of them. A ViewModel is scoped to a ViewModelStoreOwner, like an activity or a navigation destination, and the widget and service have neither.

You reach for StateStore here. You define a typed key, keep it private to the class that owns it, and expose read-only State:

<button data-code="@Serializable
sealed interface SeatHold {
@Serializable
data object None : SeatHold
@Serializable
data class Held(val bookingId: String, val expiresAtMillis: Long) : SeatHold
}
@Serializable
private data object SeatHoldKey :
StateStoreKey(defaultValue = SeatHold.None),
PersistToDataStore
class SeatHoldManager(private val stateStore: StateStore) {
val hold: State = stateStore.getState(SeatHoldKey)
fun startHold(bookingId: String, expiresAtMillis: Long) {
stateStore.setState(SeatHoldKey, SeatHold.Held(bookingId, expiresAtMillis))
}
fun release() {
stateStore.setState(SeatHoldKey, SeatHold.None)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

@Serializable
sealed interface SeatHold {
    @Serializable
    data object None : SeatHold
    @Serializable
    data class Held(val bookingId: String, val expiresAtMillis: Long) : SeatHold
}
@Serializable
private data object SeatHoldKey :
    StateStoreKey<SeatHold>(defaultValue = SeatHold.None),
    PersistToDataStore
class SeatHoldManager(private val stateStore: StateStore) {
    val hold: State<SeatHold> = stateStore.getState(SeatHoldKey)
    fun startHold(bookingId: String, expiresAtMillis: Long) {
        stateStore.setState(SeatHoldKey, SeatHold.Held(bookingId, expiresAtMillis))
    }
    fun release() {
        stateStore.setState(SeatHoldKey, SeatHold.None)
    }
}
@Serializable
sealed interface SeatHold {
    @Serializable
    data object None : SeatHold
    @Serializable
    data class Held(val bookingId: String, val expiresAtMillis: Long) : SeatHold
}
@Serializable
private data object SeatHoldKey :
    StateStoreKey<SeatHold>(defaultValue = SeatHold.None),
    PersistToDataStore
class SeatHoldManager(private val stateStore: StateStore) {
    val hold: State<SeatHold> = stateStore.getState(SeatHoldKey)
    fun startHold(bookingId: String, expiresAtMillis: Long) {
        stateStore.setState(SeatHoldKey, SeatHold.Held(bookingId, expiresAtMillis))
    }
    fun release() {
        stateStore.setState(SeatHoldKey, SeatHold.None)
    }
}

You create one StateStore at the application or DI level and inject it into managers and repositories. The guide tells you not to hand StateStore itself to UI classes. Because the key implements PersistToDataStore, one call in your Application makes it survive process death and app restarts:

applicationScope.launch {
store.syncToDataStore(
path = dataStoreFile("statestore.json").absolutePath,
coroutineScope = applicationScope,
)
}
}
val seatHoldManager = SeatHoldManager(stateStore)
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

class TravelApplication : Application() {
    val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
    val stateStore = StateStore().also { store ->
        applicationScope.launch {
            store.syncToDataStore(
                path = dataStoreFile("statestore.json").absolutePath,
                coroutineScope = applicationScope,
            )
        }
    }
    val seatHoldManager = SeatHoldManager(stateStore)
}
class TravelApplication : Application() {
    val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
    val stateStore = StateStore().also { store ->
        applicationScope.launch {
            store.syncToDataStore(
                path = dataStoreFile("statestore.json").absolutePath,
                coroutineScope = applicationScope,
            )
        }
    }
    val seatHoldManager = SeatHoldManager(stateStore)
}

Keep two things in mind. syncToDataStore suspends forever, so the code calls it inside launch. On startup, getState first returns the default value, then updates once DataStore finishes reading the file.

To release the hold on time, give the manager an application CoroutineScope and use listener, Transform’s other function. It runs a @Composable block, with no output, until something cancels its coroutine:

0) delay(remaining)
stateStore.setState(SeatHoldKey, SeatHold.None)
}
}
}
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

init {
    scope.launch {
        listener {
            val current = hold.value
            if (current is SeatHold.Held) {
                LaunchedEffect(current.expiresAtMillis) {
                    val remaining = current.expiresAtMillis - System.currentTimeMillis()
                    if (remaining > 0) delay(remaining)
                    stateStore.setState(SeatHoldKey, SeatHold.None)
                }
            }
        }
    }
}
init {
    scope.launch {
        listener {
            val current = hold.value
            if (current is SeatHold.Held) {
                LaunchedEffect(current.expiresAtMillis) {
                    val remaining = current.expiresAtMillis - System.currentTimeMillis()
                    if (remaining > 0) delay(remaining)
                    stateStore.setState(SeatHoldKey, SeatHold.None)
                }
            }
        }
    }
}

If the user pays early and the hold becomes None, the Held branch leaves composition and Compose cancels the LaunchedEffect. You don’t track a Job by hand.

Takeaway: StateStore lives at app scope, inside your managers. It’s the shared layer under your ViewModels.

🔓 So ViewModel lives, and it was never “versus”

So, does AppState replace ViewModel?

No. The guide gives the same answer on every page. The architecture table on the “Use Compose State outside the UI” page sorts state by how long it should live:

  • Live state (network status, current selection): in memory only, rebuilt on startup. Use mutableStateOf in a ViewModel or a DI-scoped @Singleton manager, with transform and listener to derive and observe it.
  • Transient UI state (scroll position, a search query, filter toggles): one screen, survives configuration changes and system-initiated process death. Use rememberSaveable or SavedStateHandle.saveable in a ViewModel.
  • Transient session state (a running timer, a checkout cart, a form draft): shared across activities, services or widgets, survives background process death. Use StateStore inside a manager or repository, with PersistToDataStore keys.
  • Permanent state (settings, app data): DataStore or Room, collected inside transform.

⚖️ AppState vs ViewModel, side by side

ViewModel appears in two of those rows. StateStore appears in one, and it’s the row ViewModel never covered well. The two compare like this:

  • Scope. A ViewModel belongs to a ViewModelStoreOwner: a screen, a nav graph, an activity. A StateStore belongs to the process, because you create it once in Application or DI.
  • Configuration changes. A ViewModel survives them. They don’t affect a StateStore, since you don’t tie it to an activity.
  • Process death. A ViewModel needs SavedStateHandle for this, and saved state is tied to that screen’s back stack entry. StateStore needs PersistToDataStore keys and syncToDataStore, and its state also survives the user closing and reopening the app.
  • Who can read it. A ViewModel is for its screen. ViewModels, composables, widgets, services and transform blocks in the same process can all read a StateStore manager. Only the same process, though: the guide says to use IPC if you need more than that.
  • Testing. Both test the same way: inject the scope. A ViewModel built with a transform should take a CoroutineScope and a CoroutineDispatcher in its constructor and pass the scope to ViewModel(coroutineScope). Then transformTest from transform-testing gives you backgroundScope, testDispatcher and advance().

@Test
fun clearsSelectionWhenQueryChanges() = transformTest {
    val viewModel = FlightSearchViewModel(
        flightsRepository = FakeFlightsRepository(),
        networkMonitor = FakeNetworkMonitor(),
        savedStateHandle = SavedStateHandle(),
        coroutineScope = backgroundScope,
        dispatcher = testDispatcher,
    )
    viewModel.toggleSelection("6E-2134")
    viewModel.updateQuery("BOM")
    advance()
    assertThat(viewModel.selectedFlightIds).isEmpty()
}
@Test
fun clearsSelectionWhenQueryChanges() = transformTest {
    val viewModel = FlightSearchViewModel(
        flightsRepository = FakeFlightsRepository(),
        networkMonitor = FakeNetworkMonitor(),
        savedStateHandle = SavedStateHandle(),
        coroutineScope = backgroundScope,
        dispatcher = testDispatcher,
    )
    viewModel.toggleSelection("6E-2134")
    viewModel.updateQuery("BOM")
    advance()
    assertThat(viewModel.selectedFlightIds).isEmpty()
}

This test assumes you added those two constructor parameters and a toggleSelection function to the earlier ViewModel, the same way the guide’s HomeViewModel does.

The real question was never AppState vs ViewModel. It’s who owns this state, and how long should it live? A screen owns it: ViewModel, now with transform if you want it. Nobody’s screen owns it: a manager over StateStore, read by as many ViewModels as you like.

⚠️ Common mistakes I’d expect in code review

  1. Exposing StateStore or its keys to the UI. The guide keeps keys private or internal and exposes read-only State from a manager. A public key is a global variable with extra steps.
  2. Persisting every tick. Every change to a PersistToDataStore key writes, and all persisted keys go into a single file. Store expiresAtMillis, not the seconds left. Debounce text input before writing it to a persisted key, and keep big data in Room.
  3. Using transform for events. It holds the current value, drops rapid intermediate updates and skips equal consecutive values. For running totals, logs, queues or one-time commands, the guide says to stay with Flow.
  4. Forgetting the build setup. Any module that calls transform or listener needs the Compose compiler plugin and Compose enabled, even a data module with no UI. Modules that only read and write State don’t.
  5. Assuming a background ViewModel goes quiet. A transform on viewModelScope keeps running while the UI is in the background.
  6. Shipping it like a stable API. It’s 1.0.0-alpha01, and the guide says the APIs may change.

✅ Checks for your own codebase today

  • List your @Singleton classes that hold a MutableStateFlow. The ones shared by a widget, a service or several activities are your StateStore candidates.
  • Find ViewModels with a combine of four or five flows. Those are where transform would read best, once you’re comfortable with alpha.
  • Check which screen state needs SavedStateHandle, and which is session state that should outlive the screen.
  • Leave the rest alone. A ViewModel exposing a StateFlow is still a fine ViewModel.

🎯 TL;DR

Is ViewModel dead? No. Jetpack AppState (1.0.0-alpha01, October 28, 2026) is two multiplatform libraries on the Compose runtime. Transform runs a UI-less @Composable block to produce State, and listener observes it. StateStore is a typed, app-scoped container whose keys can persist through DataStore. It doesn’t replace ViewModel. The guide uses transform inside ViewModels with viewModelScope, and puts StateStore in managers that ViewModels, widgets and services read. Pick by owner and lifetime: screen state stays in a ViewModel, shared session state goes to a manager over StateStore.

Source: the official AppState guide, with its Transform, StateStore and Use Compose State outside the UI pages.

break-time:_ If you are enjoying this, you will like this one as well. Do explore it after reading the current one. Thank you!_

The Enum Value Your App Has Never Seen

Hi Guys 👋! I have over 9 years of solid experience in Kotlin and Android development, Feel free to explore my portfolio and GitHub contributions. If your company needs a Android developer, drop me a mail at [email protected]. You can also connect with me on LinkedIn. Let’s chat about how I can bring my expertise to your team!

Thank you for reading until the end. Before you go:

For Social Stalking 👀: LinkedIn | Twitter | StackOverflow | Github | Youtube | About Me

Enjoying the Post? a clap is much appreciated if you enjoyed. No sign up or cost associated 🙂 If you want to support my content do consider dropping a tip/coffee/donation reach me out of my email.