Search code examples
androidandroid-roomandroid-architecture-components

What is the perfect use case for using Room.inMemoryDatabaseBuilder()?


So I am creating this application where there are lots of personal information and data which shouldn't be persisted in the device to avoid security issues. When learning about Room, I came across this Room.inMemoryDatabaseBuilder() which as the documentation states:

Creates a RoomDatabase.Builder for an in memory database. Information stored in an in memory database disappears when the process is killed. Once a database is built, you should keep a reference to it and re-use it.

I was wondering whether this would be a perfect usecase for my situation. Since the data will only exist in memory and not stored in the device.

It seems like a good idea. My only concern is that I haven't seen an implementation of this in an actual application yet. The only usecase which I saw this Room.inMemoryDatabaseBuilder() used was for testing (so then you don't have to worry about database clean-up on each and every test run).

Can anyone offer some advice? It would be much appreciated.

Thank you very much.


Solution

  • I posted this same context question in @Florina Muntenescu Blog here

    Her answer was:

    Hi, Yes, it can be used for any use case that requires the data to be kept in memory only. Testing is one of them.

    So basically, Room.inMemoryDatabaseBuilder() can be used for other use cases where data should only be kept in memory.