Room Across Processes
Most Android apps run in a single process. However, Android does give developers the option to have their apps be split across multiple processes.
However, this can cause problems with stuff held in memory, as multiple processes will not share that memory. In the case of Room, one area where the problem crops up is with “invalidation tracking”: the piece of Room that knows to update your reactive query results (
Observable, etc.) when the data changes. By default, that does not work across process boundaries, but you can enable it via
enableMultiInstanceInvalidation() on your
In this chapter, we will explore all of this in greater detail and demonstrate how it works.
Room and Invalidation Tracking
When you modify your Room database, active observers of reactive responses from
@Query-annotated functions get fresh results delivered automatically.
Under the covers, that is powered by
InvalidationTracker and related code. Room tracks:
- Which tables and views are referenced by active queries, and
- Which tables are affected by database modifications
When you modify the database, Room looks up the active queries that are tied to any tables that you affected. For those, Room re-executes the queries and emits new results via the
Observable, or whatever.
This is all done for you, almost by magic. But, in reality, it just sophisticated code from a sophisticated library.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.