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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.