ViewModel vs Saved Instance State
While saved instance state stores an activity record across process death, it also stores an activity record across a configuration change. When you first launch the activity, the saved instance state bundle is null. When you rotate the device, the OS calls onSaveInstanceState(Bundle) on your activity. The OS then passes the data you stashed in the bundle to onCreate(Bundle?).
If saved instance state protects from both configuration changes and process death, why bother with a ViewModel at all? To be fair, GeoQuiz is so simple that you could have gotten away with saved instance state only.
However, most apps do not rely on a small, hardcoded question bank data set like GeoQuiz does. Most apps ...
Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.