Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Keeping the Changes Flowing
At this point, your database has been fully set up and connected to your UI. However, your current code is only suited to query the database once. Eventually, you will be able to add and update individual crimes – but at the moment, if other parts of your app tried to update the database, CrimeListFragment would be oblivious to the changes and would happily present stale data.
While you could add code to manually reconcile updates from specific parts of your app, it would be better to “observe” the database so that CrimeListFragment automatically receives all updates to the database, regardless of where they come from.
Which brings us back to coroutines, along with two new classes: Flow and StateFlow. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access