I have 3 fragments in my bottom nav and their View...
# android
f
I have 3 fragments in my bottom nav and their ViewModels stay in memory to preserve their state (the fragments are only detached, not removed). Is it okay that these ViewModels keep getting database updates even if the fragment is not active? I'm using the
stateIn
operator so that a Flow that starts fetching new data doesn't cancel when we switch screens. But after that remote fetch is done, the Flow will keep emitting cached data from the DB (which could get updated indirectly from another screen) even if the fragment is not active.
o
In my opinion: It's fine, don't worry about it. Keep the
(List<DbModel>) -> ViewState
mapping off the main thread and forget about it. Unless you're doing some very heavy computations or have many-Megabyte query results, in which case you might be wasting a little bit too much CPU or memory. But I assume you aren't doing anything fancy, just like most of us.
f
Thank you. I'm just retrieving updates from Room, I guess that's not too CPU intensive
e
But I assume you aren't doing anything fancy, just like most of us.
I feel seen 🤣