When / How to Create / Destroy Room Database

微笑、不失礼 提交于 2021-02-11 13:38:39

问题


I was wondering if someone could either point me to documentation to / clarify when to create or destroy a room database instance. Also how you would effectively open / close it ?

If I have a RoomDatabase object that gets injected via dagger to a presenter is that cool and then I just access various Daos? I'm worried about having the object lingering and taking up memory.


回答1:


Instead of Injecting the RoomDatabase into your presenter you could Inject a DataManager Singleton class.

This DataManager can hold your WeakReferences to your DAOs . Based on when you try to access the data, first check if you have it in memory pass it on to the presenter, if not you can then Lazily access the RoomDB to load data into memory and then pass on to the presenter.

In this way, there is a Single Source of Truth that accesses/manages your data.



来源:https://stackoverflow.com/questions/51031574/when-how-to-create-destroy-room-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!