I wonder if it is okay to use the same Room db in Activity and Remote Service.
Since the Service is remote it resides in a separate process. Is it okay to open the same sqlite db file simultaneously from the Remote Service and the Activity itself? Whether their operations must be manually synchronized via some sort of IPC ?
I mean imagine two writes at the same time initiated by the Remote Service and the Acitivity. Is it error prone or it is handled properly by the Room itself ?
Yes, it’s fine.
SQLite handles locking across processes, so your Activity and remote Service can use the same Room database safely. Reads can happen in parallel, and writes are serialized - no corruption, no need for manual IPC sync just for that.
The real catch is Room itself: each process has its own instance, so observers (Flow, LiveData, etc.) won’t see changes from the other process unless you enable:
.enableMultiInstanceInvalidation()
One thing to keep in mind: SQLite prevents corruption, not logic bugs. If both sides read → compute → write, you can still have race conditions. Use transactions or atomic queries when it matters.
Corentin Houdayer