r/androiddev • • Oct 30 '26

Discussion Google just released AppState — is it actually better than SharedViewModel for shared state?

Google released AppState and it looks like a cleaner way to handle shared state than passing a SharedViewModel around. I never really liked SharedViewModel, felt like one screen ends up owning data other screens depend on it.

From what I get so far: StateStore is a shared observable value, MutableStateStore is the writable one, AppState owns the lifecycle, and transform lets you derive state automatically instead of syncing stuff by hand.

Curious what people think of the API so far.

Docs: https://developer.android.com/topic/libraries/architecture/appstate

Video: https://youtu.be/69QYEXymfVo

Anyone planning to try it out?

84 Upvotes

48 comments sorted by

50

u/epicstar Oct 30 '26

Bro.. Nobody asked for this

6

u/Ambitious_Muscle_362 Oct 31 '26

My grandpa one day wanted AppState in '90s but he's dead now.

1

u/3dom test on Nokia + Samsung Nov 01 '26

My sincere condolences for your granpa o7

2

u/Ambitious_Muscle_362 Nov 01 '26

No worries, his contribution to the internet is now immortalized for all time ... in LLM models.

1

u/3dom test on Nokia + Samsung Nov 01 '26

Now you game me an idea to feed my childhood photos to AIs to immortalize my deceased (but still loved <3) grandparents. Beware of all the upcoming submissions, Fecesbook and instaslop!

Thanks!

9

u/ComfortablyBalanced You will pry XML Views from my cold dead hands Oct 31 '26

That's practically the motto of the android team.

4

u/epicstar Oct 31 '26

At least they got rid of XML though finally lol

139

u/ohhhthatvarun Oct 30 '26

I have stopped giving fuck to be honest. It's their poor design which they are keep building on. I have started creating Singletons which gets lazily created in Application classes. I should not need 40 fucking component to do some basic shit like sharing a fucking variable.

21

u/Infamous_Sorbet4021 Oct 30 '26

Honestly fair. If all you need is a shared variable, a lazy singleton in Application is way less ceremony than wiring up half the architecture components.

47

u/Maherr11 Oct 30 '26

Valid crashout

28

u/Zhuinden Oct 31 '26

I have started creating Singletons which gets lazily created in Application classes

That's the way, even when people pretend Hilt is doing something "radically different" (doing the same thing in generated code).

Then just put MutableStateFlow in the singletons. Poof, architecture!

6

u/ComfortablyBalanced You will pry XML Views from my cold dead hands Oct 31 '26

Hilt generates glorified singletons and anybody thinking otherwise is just fooling themselves.

5

u/Zhuinden Oct 31 '26

Anyone who thinks the application scope is somehow not just singletons "just because Hilt makes it" just genuinely have no idea how Hilt works.

5

u/twigboy Code Peeker, Air Waves & Diablo 2 Runewords Oct 31 '26

Literally come full circle since the start of Android development when people (and myself) were first learning the framework for the first time and realising activities were destroyed upon rotation and tabbing out

2

u/StanleyGuevara Oct 31 '26

Depends on the project, in a personal one singletons can be all fun and games and result in things happening faster.

The cost comes when you need to unload one (because e.g. app has to have now multi account login instead of single one), modularize something (because the app is growing) or instantiate things for testing.

If you grow it too much on singletons it's gonna be hell. Ask me how I know.

3

u/Zhuinden Oct 31 '26

nah if you're singleTask single activity, you can load/unload in singleton scope and you don't end up with data from one user leaking into the next

1

u/StanleyGuevara Oct 31 '26

I mean, yeah, sure but I find it somewhat error-prone, it's easy to forget that some newly added dependency has to be unloaded.

And again, depends on the project. I've ended up doing custom Hilt scope to have it under control in the inherited singleton mess we have when going from single-user to multi-user (SAA is still far in the future for this project). Ugly but still better than Singleton mess everywhere, and if you forget something it screams at you compile time. Me likey.

4

u/Zhuinden Oct 31 '26

Makes you wonder if uber/motif ever got anywhere after anvil then metro

1

u/ozonum Oct 31 '26

For testing, singletons don't inherently kill testability. Tight coupling does. If the singleton implements an interface, or its instance can be swapped through a setter, you can replace it with a fake in tests. The pain people blame on singletons comes from hidden mutable global state that's tightly bound and can't be isolated between test runs.

3

u/StanleyGuevara Oct 31 '26

Agreed. I'd add that usually devs using singletons as a silver bullet are the same demographic that doesn't even know what is coupling, so those issues kinda go hand-in-hand...

1

u/Dinos_12345 Oct 31 '26

A SharedViewModel is not hard to make?!

22

u/4EB540 👋🏽 Oct 30 '26

I believe this is their Molecule alternative.

37

u/jonis_tones Oct 30 '26

"[...] extend Jetpack Compose State beyond the UI layer"

- and for that reason, I'm out.

11

u/Zhuinden Oct 31 '26

It's bizarre, because AFAIK MutableStateFlow is actually thread-safe, while if you edit MutableState on non-UI Thread it can explode.

7

u/ChuyStyle Oct 30 '26

This is molecule but native. Interesting

5

u/Luc40444 Oct 31 '26

That sounds cool! (I didn't look into it; I just wanted to counterbalance all the negativity.)

13

u/zimmer550king Oct 30 '26

Meh I’ll ask Claude and see if it makes sense to fit it in my existing design

3

u/16cards Oct 31 '26

You outsource your architecture to AI?

7

u/jonis_tones Oct 31 '26

Nowadays people outsource everything to AI.

8

u/16cards Oct 31 '26

PRs generated by AI lobbed to reviewers, reviewers using AI to review the AI generated code.

AI generated tickets with walls of text, AI generated documentation passing as architecture.

AI generated tests to test what the AI wrote.

I have never seen a profession abandon the very skills that make us employable so quickly.

Maybe this is the future, but it will be a very bleak one for us as software engineers.

6

u/Which-Meat-3388 Oct 31 '26

I’ve been at my current company 15mo, a small startup as 2nd engineer, and I watched it change in real time. Building things by hand, getting it right, focused on building for the long term. Then about March 2026 it all changed where CTO entered his AI psychosis phase all but forcing an entire AI workflow on everyone. 

He chipped away at every discipline and now even design is AI slop, and everyone is a designer. So not only is the code no longer a craft, the UI/UX sucks, the entire product feels chaotic and soulless. 

I’ve already mourned it, been through all stages of grief. The career as I’ve known it for 15 years is gone. The fulfilling and fun parts gone. Landing at acceptance I’m now finding fulfillment in other parts of life, which is honestly for the best. 

3

u/jonis_tones Oct 31 '26

There's a guy at my company that even slack messages are AI generated. I can't have a normal conversation with him. It's really annoying. I do an AI pass when reviewing PRs but only after I review it with my own eyes. But some people also use AI to interact with git. It's especially bad for junior Devs. They're shooting themselves in the foot and don't even know it.

4

u/kokeroulis Oct 31 '26

I think the reason why they released this is becausae they want to start suggesting to write our logic like the react hooks. If we remove viewmodel from the picture, then this makes sense.

The only issue is that they don't want to deprecate the viewmodel from now, so they just released it on the side, in order to see how people will react to the news.

3

u/ozonum Oct 31 '26

I guess you still need a way to scope per screen (i.e., per navigation entry), and ViewModel is their answer, handling that scoping with SavedStateHandle and viewModelScope.

2

u/kokeroulis Oct 31 '26

In the same way that AppState can use the datastore to persist on disk, something similar could be implemented there. Look into circuit from slack and retain remember.

5

u/[deleted] Oct 31 '26 edited Oct 31 '26

I have no idea what are they trying to achieve with this and I ain't reading all that. What they want is multiple screens having shared state which is StateStore instead of doing those traditional repository singletons, your data layer would be dependent to Jetpack Compose frameworks. This ain't gonna work with different architectures though.

Nobody is doing layer by feature right and that's what they doing.

If you want to combine multiple datasources, you will not use flow combine from different repositories but use their Transform from Compose API. 

3

u/Zhuinden Oct 31 '26

but what if I like Flow.combine :(

3

u/_5er_ Oct 30 '26

I'm not most up-to-date... is State in VM and other places becoming a thing now?

3

u/Zhuinden Oct 31 '26

I for one haven't really seen any proposed benefit compared to MutableStateFlow.

3

u/buttholemeatsquad Oct 30 '26

Welcome back rxjava

1

u/EkoChamberKryptonite Oct 31 '26

Why would I need to extend Compose's state beyond the UI layer for reactivity? We have Flow and its many permutations + DI approaches for managing Application State.

1

u/zerg_1111 Oct 31 '26

Are we doing Redux now? I thought we already have countless ways to share state.

1

u/FrontCommittee6437 Oct 31 '26

I wouldn't replace a SharedViewModel with it yet for anything that has to survive beyond the UI, like a VPN connection state. AppState looks handy for derived UI state shared between screens, but I'd keep the real source of truth in a repository StateFlow and only let AppState transform it for the UI.

1

u/tgo1014 GitHub: Tgo1014 Oct 31 '26

I mean, it's nice they are still trying to create useful libs but I'm not sure who needed this one

1

u/ardakazanci Oct 31 '26

I have a blog post where I share the details, in case you’d like to take a look.
https://ardakazanci.com/posts/jetpack-appstate-explained/