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. ...

Get Android Programming: The Big Nerd Ranch Guide, 5th 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.