https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
o

Ofir Bar

02/12/2020, 8:43 AM
Hey guys, Say I have one Activity with a RecyclerView. You can choose items on the RecyclerView. It is important that if the user minimizes the app and gets back to it after hours he still will see the selected items on the RecyclerView. The Activity is forced to be in portrait mode only, set from the manifest using:
Copy code
android:screenOrientation="portrait"
Do I have any good reason to make a ViewModel for this Activity? I know that users can’t rotate the screen. What I am asking, is that in this scenario, do the ViewModel have “higher survival rate” than the Activity?
s

satyan

02/12/2020, 9:03 AM
This contains the answer to your non-Kotlin-specific question 😉 https://developer.android.com/topic/libraries/architecture/saving-states
o

Ofir Bar

02/12/2020, 9:07 AM
@satyan Cheers mate 😄 🍻
t

tschuchort

02/12/2020, 10:30 AM
You need to save state across process death. ViewModel itself won't help with that and isn't necessary here. There is the new SavedStateContainer or whatever it's called but you can just save to bundle yourself.
a

Anastasia Finogenova

02/12/2020, 5:54 PM
You should have a view model for a reason of presentation logic separation and testability, or do you mean Presenter vs ViewModel?
3 Views